Ready to get started?

Download a free trial of the GraphQL Data Provider to get started:

 Download Now

Learn more:

GraphQL Icon GraphQL ADO.NET Provider

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

Automate GraphQL Integration Tasks from PowerShell



Are you in search of a quick and easy way to access GraphQL data from PowerShell? This article demonstrates how to utilize the GraphQL Cmdlets for tasks like connecting to GraphQL data, automating operations, downloading data, 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.

PowerShell Cmdlets or ADO.NET Provider?

The Cmdlets are not only a PowerShell interface to GraphQL, 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.

Once you have acquired the necessary connection properties, accessing GraphQL data in PowerShell can be enabled in three 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 }