Automate GraphQL Integration Tasks from PowerShell

Ready to get started?

Download for a free trial:

Download Now

Learn more:

GraphQL ADO.NET Provider

Rapidly create and deploy powerful .NET applications that integrate with GraphQL.



Are you looking for a quick and easy way to access GraphQL data from PowerShell? We show how to use the Cmdlets for GraphQL and the CData ADO.NET Provider for GraphQL to connect to GraphQL data and synchronize, automate, download, and more.

The CData Cmdlets for GraphQL are standard PowerShell cmdlets that make it easy to accomplish data cleansing, normalization, backup, and other integration tasks by enabling real-time access to GraphQL.

Cmdlets or ADO.NET?

The cmdlets are not only a PowerShell interface to the GraphQL API, but also an SQL interface; this tutorial shows how to use both to retrieve GraphQL data. We also show examples of the ADO.NET equivalent, which is possible with the CData ADO.NET Provider for GraphQL. To access GraphQL data from other .NET applications, like LINQPad, use the CData ADO.NET Provider for GraphQL.

After obtaining the needed connection properties, accessing GraphQL data in PowerShell consists of three basic steps.

You must specify the URL of the GraphQL service. The driver supports two types of authentication:

  • Basic: Set AuthScheme to Basic. You must specify the User and Password of the GraphQL service.
  • OAuth 1.0 & 2.0: Take a look at the OAuth section in the Help documentation for detailed instructions.

PowerShell

  1. Install the module:

    Install-Module GraphQLCmdlets
  2. Connect:

    $graphql = Connect-GraphQL -AuthScheme "$AuthScheme" -User "$User" -Password "$Password" -URL "$URL"
  3. Search for and retrieve data:

    $userlogin = "admin" $users = Select-GraphQL -Connection $graphql -Table "Users" -Where "UserLogin = `'$UserLogin`'" $users

    You can also use the Invoke-GraphQL cmdlet to execute SQL commands:

    $users = Invoke-GraphQL -Connection $graphql -Query 'SELECT * FROM Users WHERE UserLogin = @UserLogin' -Params @{'@UserLogin'='admin'}

ADO.NET

  1. Load the provider's assembly:

    [Reflection.Assembly]::LoadFile("C:\Program Files\CData\CData ADO.NET Provider for GraphQL\lib\System.Data.CData.GraphQL.dll")
  2. Connect to GraphQL:

    $conn= New-Object System.Data.CData.GraphQL.GraphQLConnection("AuthScheme=Basic;User=username;Password=password;URL=https://mysite.com;InitiateOAuth=GETANDREFRESH") $conn.Open()
  3. Instantiate the GraphQLDataAdapter, execute an SQL query, and output the results:

    $sql="SELECT Name, Email from Users" $da= New-Object System.Data.CData.GraphQL.GraphQLDataAdapter($sql, $conn) $dt= New-Object System.Data.DataTable $da.Fill($dt) $dt.Rows | foreach { Write-Host $_.name $_.email }