John Black
John Black

Reputation: 21

How can I execute Graphql query?

Please, give an easy example how to execute query. I found some examples on the net but they are not working.

Like

GraphqlClient client = new GraphqlClient("example.com\graphql");
String query = "query {getClient(condition){clientName, clientID}}"
var response = client.executeQuery(query);

Upvotes: 1

Views: 4423

Answers (1)

Arjit Sharma
Arjit Sharma

Reputation: 466

This should work fine:

var graphQLOptions = new GraphQLHttpClientOptions
        {
            EndPoint = new Uri("example.com\graphql", UriKind.Absolute),
        };
       var graphQLClient = new GraphQLHttpClient(graphQLOptions, new NewtonsoftJsonSerializer());

       var msg = new GraphQLRequest
        {
            Query = "query {getClient(condition){clientName, clientID}}"
        };
       var graphQLResponse = await graphQLClient.SendQueryAsync<dynamic>(msg).ConfigureAwait(false);

Upvotes: 1

Related Questions