Skip to content

raphaabreu/graphql-client

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

About

A GraphQL Client for .NET Standard

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • C# 100.0%