All Projects → graphql-dotnet → Graphql Client

graphql-dotnet / Graphql Client

Licence: mit
A GraphQL Client for .NET Standard

Projects that are alternatives of or similar to Graphql Client

Graphql
Package graphql provides a GraphQL client implementation.
Stars: ✭ 467 (+11.72%)
Mutual labels:  graphql, client
Graphql Zeus
GraphQL client and GraphQL code generator with GraphQL autocomplete library generation ⚡⚡⚡ for browser,nodejs and react native
Stars: ✭ 1,043 (+149.52%)
Mutual labels:  graphql, client
Graphql Client
Typed, correct GraphQL requests and responses in Rust
Stars: ✭ 620 (+48.33%)
Mutual labels:  graphql, client
Ether.network
https://github.com/Eastrall/Sylver
Stars: ✭ 147 (-64.83%)
Mutual labels:  netstandard, client
Graphql Typed Client
A tool that generates a strongly typed client library for any GraphQL endpoint. The client allows writing GraphQL queries as plain JS objects (with type safety, awesome code completion experience, custom scalar type mapping, type guards and more)
Stars: ✭ 194 (-53.59%)
Mutual labels:  graphql, client
Graphql
Simple low-level GraphQL HTTP client for Go
Stars: ✭ 682 (+63.16%)
Mutual labels:  graphql, client
Githubv4
Package githubv4 is a client library for accessing GitHub GraphQL API v4 (https://docs.github.com/en/graphql).
Stars: ✭ 760 (+81.82%)
Mutual labels:  graphql, client
Subscriptions Transport Sse
A Server-Side-Events (SSE) client + server for GraphQL subscriptions
Stars: ✭ 55 (-86.84%)
Mutual labels:  graphql, client
Graphlient
Ruby GraphQL Client
Stars: ✭ 142 (-66.03%)
Mutual labels:  graphql, client
Graphql client
GraphQL Client.
Stars: ✭ 78 (-81.34%)
Mutual labels:  graphql, client
Re Graph
A graphql client for clojurescript and clojure
Stars: ✭ 366 (-12.44%)
Mutual labels:  graphql, client
Graphql Flutter
A GraphQL client for Flutter, bringing all the features from a modern GraphQL client to one easy to use package.
Stars: ✭ 2,811 (+572.49%)
Mutual labels:  graphql, client
Graphql Ws
Coherent, zero-dependency, lazy, simple, GraphQL over WebSocket Protocol compliant server and client.
Stars: ✭ 398 (-4.78%)
Mutual labels:  graphql, client
Apollo Errors
Machine-readable custom errors for Apollostack's GraphQL server
Stars: ✭ 405 (-3.11%)
Mutual labels:  graphql
Elasticsearch Rs
Official Elasticsearch Rust Client
Stars: ✭ 412 (-1.44%)
Mutual labels:  client
Reactjs101
從零開始學 ReactJS(ReactJS 101)是一本希望讓初學者一看就懂的 React 中文入門教學書,由淺入深學習 ReactJS 生態系 (Flux, Redux, React Router, ImmutableJS, React Native, Relay/GraphQL etc.)。
Stars: ✭ 4,004 (+857.89%)
Mutual labels:  graphql
Yakyak
Desktop chat client for Google Hangouts
Stars: ✭ 3,869 (+825.6%)
Mutual labels:  client
Typegql
Create GraphQL schema with TypeScript classes.
Stars: ✭ 415 (-0.72%)
Mutual labels:  graphql
Nheko
No longer maintained - Desktop client for the Matrix protocol (active fork https://github.com/Nheko-Reborn)
Stars: ✭ 410 (-1.91%)
Mutual labels:  client
Graphql Api
Write type-safe GraphQL services in Haskell
Stars: ✭ 404 (-3.35%)
Mutual labels:  graphql

GraphQL.Client

A GraphQL Client for .NET Standard over HTTP.

Provides the following packages:

Package Downloads Nuget Latest
GraphQL.Client Nuget Nuget
GraphQL.Client.Abstractions Nuget Nuget
GraphQL.Client.Abstractions.Websocket Nuget Nuget
GraphQL.Client.LocalExecution Nuget Nuget
GraphQL.Client.Serializer.Newtonsoft Nuget Nuget
GraphQL.Client.Serializer.SystemTextJson Nuget Nuget
GraphQL.Primitives Nuget Nuget

Specification:

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

Usage:

Create a GraphQLHttpClient

// To use NewtonsoftJsonSerializer, add a reference to NuGet package GraphQL.Client.Serializer.Newtonsoft
var graphQLClient = new GraphQLHttpClient("https://api.example.com/graphql", new NewtonsoftJsonSerializer());

Create a GraphQLRequest:

Simple Request:

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

OperationName and Variables Request:

var personAndFilmsRequest = new GraphQLRequest {
    Query =@"
    query PersonAndFilms($id: ID) {
        person(id: $id) {
            name
            filmConnection {
                films {
                    title
                }
            }
        }
    }",
    OperationName = "PersonAndFilms",
    Variables = new {
        id = "cGVvcGxlOjE="
    }
};

Be careful when using byte[] in your variables object, as most JSON serializers will treat that as binary data! If you really need to send a list of bytes with a byte[] as a source, then convert it to a List<byte> first, which will tell the serializer to output a list of numbers instead of a base64-encoded string.

Execute Query/Mutation:

public class ResponseType 
{
    public PersonType Person { get; set; }
}

public class PersonType 
{
    public string Name { get; set; }
    public FilmConnectionType FilmConnection { get; set; }    
}

public class FilmConnectionType {
    public List<FilmContentType> Films { get; set; }    
}

public class FilmContentType {
    public string Title { get; set; }
}

var graphQLResponse = await graphQLClient.SendQueryAsync<ResponseType>(personAndFilmsRequest);

var personName = graphQLResponse.Data.Person.Name;

Using the extension method for anonymously typed responses (namespace GraphQL.Client.Abstractions) you could achieve the same result with the following code:

var graphQLResponse = await graphQLClient.SendQueryAsync(personAndFilmsRequest, () => new { person = new PersonType()} );
var personName = graphQLResponse.Data.person.Name;

Use Subscriptions

public class UserJoinedSubscriptionResult {
    public ChatUser UserJoined { get; set; }

    public class ChatUser {
        public string DisplayName { get; set; }
        public string Id { get; set; }
    }
}

Create subscription

var userJoinedRequest = new GraphQLRequest {
    Query = @"
    subscription {
        userJoined{
            displayName
            id
        }
    }"
};

IObservable<GraphQLResponse<UserJoinedSubscriptionResult>> subscriptionStream 
    = client.CreateSubscriptionStream<UserJoinedSubscriptionResult>(userJoinedRequest);

var subscription = subscriptionStream.Subscribe(response => 
    {
        Console.WriteLine($"user '{response.Data.UserJoined.DisplayName}' joined")
    });

End Subscription

subscription.Dispose();

Useful Links:

Blazor WebAssembly Limitations

Blazor WebAssembly differs from other platforms as it does not support all features of other .NET runtime implementations. For instance, the following WebSocket options properties are not supported and will not be set:

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].