A GraphQL Client for .NET Standard
Clone or download
Latest commit 3fbe621 Nov 6, 2018

README.md

GraphQL.Client:

CircleCI NuGet MyGet

A GraphQL Client for .NET Standard over HTTP.

Specification:

The Library will try to follow the following standards and documents: GraphQL Specification GraphQL HomePage

Usage:

Create a GraphQLRequest:

Simple Request:

var heroRequest = new GraphQLRequest {
  Query = @"
    {
      hero {
        name
      }
    }"
};

OperationName and Variables Request:

var heroAndFriendsRequest = new GraphQLRequest {
  Query = @"
    query HeroNameAndFriends($episode: Episode) {
      hero(episode: $episode) {
        name
        friends {
          name
        }
      }
    }",
  OperationName = "HeroNameAndFriends",
  Variables = new {
    episode = "JEDI"
  }
};

Send Request:

var graphQLClient = new GraphQLClient("https://swapi.apis.guru/");
var graphQLResponse = await graphQLClient.PostAsync(heroRequest);

Read GraphQLResponse:

Dynamic:

var graphQLResponse = await graphQLClient.PostAsync(heroRequest);
var dynamicHeroName = graphQLResponse.Data.hero.name.Value; //Value of data->hero->name

Typed:

var graphQLResponse = await graphQLClient.PostAsync(heroRequest);
var personType = graphQLResponse.GetDataFieldAs<Person>("hero"); //data->hero is casted as Person
var name = personType.Name;

Useful Links:

StarWars Example Server (GitHub) StarWars Example Server (EndPoint)

GitHub GraphQL API Docs GitHub GraphQL Explorer GitHub GraphQL Endpoint