![]() |
VOOZH | about |
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.
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:
Install the module:
Install-Module GraphQLCmdlets
Connect:
$graphql = Connect-GraphQL -AuthScheme "$AuthScheme" -User "$User" -Password "$Password" -URL "$URL" -InitiateOAuth "$InitiateOAuth"
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'}
Load the provider's assembly:
[Reflection.Assembly]::LoadFile("C:\Program Files\CData\CData ADO.NET Provider for GraphQL\lib\System.Data.CData.GraphQL.dll")
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()
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
}
Download a free trial of the GraphQL Data Provider to get started:
Download NowLearn more:
👁 GraphQL IconRapidly create and deploy powerful .NET applications that integrate with GraphQL.