{"id":13451314,"url":"https://github.com/graphql-dotnet/graphql-client","last_synced_at":"2025-05-14T12:07:58.243Z","repository":{"id":27282593,"uuid":"113196300","full_name":"graphql-dotnet/graphql-client","owner":"graphql-dotnet","description":"A GraphQL Client for .NET Standard","archived":false,"fork":false,"pushed_at":"2024-07-10T17:50:41.000Z","size":1093,"stargazers_count":634,"open_issues_count":103,"forks_count":134,"subscribers_count":20,"default_branch":"master","last_synced_at":"2025-04-14T23:16:52.839Z","etag":null,"topics":["client","csharp","dotnet","graphql","netstandard"],"latest_commit_sha":null,"homepage":"","language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/graphql-dotnet.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2017-12-05T15:02:26.000Z","updated_at":"2025-03-17T11:36:25.000Z","dependencies_parsed_at":"2024-01-23T21:19:16.584Z","dependency_job_id":"888fd837-6d4b-4b2c-8a74-867055f70967","html_url":"https://github.com/graphql-dotnet/graphql-client","commit_stats":{"total_commits":696,"total_committers":22,"mean_commits":"31.636363636363637","dds":0.6666666666666667,"last_synced_commit":"fbf37dfff2830e36a45296079bac27ec60fad550"},"previous_names":[],"tags_count":47,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/graphql-dotnet%2Fgraphql-client","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/graphql-dotnet%2Fgraphql-client/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/graphql-dotnet%2Fgraphql-client/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/graphql-dotnet%2Fgraphql-client/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/graphql-dotnet","download_url":"https://codeload.github.com/graphql-dotnet/graphql-client/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248975329,"owners_count":21192210,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["client","csharp","dotnet","graphql","netstandard"],"created_at":"2024-07-31T07:00:51.644Z","updated_at":"2025-04-14T23:17:00.501Z","avatar_url":"https://github.com/graphql-dotnet.png","language":"C#","funding_links":[],"categories":["C#","Libraries","C\\#","C# #"],"sub_categories":[".NET Libraries"],"readme":"# GraphQL.Client\n\nA GraphQL Client for .NET Standard over HTTP.\n\nProvides the following packages:\n\n| Package | Downloads | Nuget Latest | \n|---------|-----------|--------------|\n| GraphQL.Client | [![Nuget](https://img.shields.io/nuget/dt/GraphQL.Client)](https://www.nuget.org/packages/GraphQL.Client/) | [![Nuget](https://img.shields.io/nuget/vpre/GraphQL.Client)](https://www.nuget.org/packages/GraphQL.Client) | \n| GraphQL.Client.Abstractions | [![Nuget](https://img.shields.io/nuget/dt/GraphQL.Client.Abstractions)](https://www.nuget.org/packages/GraphQL.Client.Abstractions) | [![Nuget](https://img.shields.io/nuget/vpre/GraphQL.Client.Abstractions)](https://www.nuget.org/packages/GraphQL.Client.Abstractions) |\n| GraphQL.Client.Abstractions.Websocket | [![Nuget](https://img.shields.io/nuget/dt/GraphQL.Client.Abstractions.Websocket)](https://www.nuget.org/packages/GraphQL.Client.Abstractions.Websocket) | [![Nuget](https://img.shields.io/nuget/vpre/GraphQL.Client.Abstractions.Websocket)](https://www.nuget.org/packages/GraphQL.Client.Abstractions.Websocket) |\n| GraphQL.Client.LocalExecution | [![Nuget](https://img.shields.io/nuget/dt/GraphQL.Client.LocalExecution)](https://www.nuget.org/packages/GraphQL.Client.LocalExecution) | [![Nuget](https://img.shields.io/nuget/vpre/GraphQL.Client.LocalExecution)](https://www.nuget.org/packages/GraphQL.Client.LocalExecution) | \n| GraphQL.Client.Serializer.Newtonsoft | [![Nuget](https://img.shields.io/nuget/dt/GraphQL.Client.Serializer.Newtonsoft)](https://www.nuget.org/packages/GraphQL.Client.Serializer.Newtonsoft) | [![Nuget](https://img.shields.io/nuget/vpre/GraphQL.Client.Serializer.Newtonsoft)](https://www.nuget.org/packages/GraphQL.Client.Serializer.Newtonsoft) | \n| GraphQL.Client.Serializer.SystemTextJson | [![Nuget](https://img.shields.io/nuget/dt/GraphQL.Client.Serializer.SystemTextJson)](https://www.nuget.org/packages/GraphQL.Client.Serializer.SystemTextJson) | [![Nuget](https://img.shields.io/nuget/vpre/GraphQL.Client.Serializer.SystemTextJson)](https://www.nuget.org/packages/GraphQL.Client.Serializer.SystemTextJson) | \n| GraphQL.Primitives | [![Nuget](https://img.shields.io/nuget/dt/GraphQL.Primitives)](https://www.nuget.org/packages/GraphQL.Primitives/) | [![Nuget](https://img.shields.io/nuget/vpre/GraphQL.Primitives)](https://www.nuget.org/packages/GraphQL.Primitives) | \n\n## Specification\nThe Library will try to follow the following standards and documents:\n\n* [GraphQL Specification](https://spec.graphql.org/June2018/)\n* [GraphQL HomePage](https://graphql.org/learn)\n\n## Usage\n\nThe intended use of `GraphQLHttpClient` is to keep one instance alive per endpoint (obvious in case you're\noperating full websocket, but also true for regular requests) and is built with thread-safety in mind.\n\n### Create a GraphQLHttpClient\n\n```csharp\n// To use NewtonsoftJsonSerializer, add a reference to \n// NuGet package GraphQL.Client.Serializer.Newtonsoft\nvar graphQLClient = new GraphQLHttpClient(\n    \"https://api.example.com/graphql\", \n    new NewtonsoftJsonSerializer());\n```\n\n\u003e [!NOTE]\n\u003e *GraphQLHttpClient* is meant to be used as a single long-lived instance per endpoint (i.e. register as singleton in a DI system), which should be reused for multiple requests.\n\n### Create a GraphQLRequest:\n#### Simple Request:\n```csharp\nvar heroRequest = new GraphQLRequest {\n    Query = \"\"\"\n    {\n        hero {\n            name\n        }\n    }\n    \"\"\"\n};\n```\n\n#### OperationName and Variables Request:\n\n```csharp\nvar personAndFilmsRequest = new GraphQLRequest {\n    Query =\"\"\"\n    query PersonAndFilms($id: ID) {\n        person(id: $id) {\n            name\n            filmConnection {\n                films {\n                    title\n                }\n            }\n        }\n    }\n    \"\"\",\n    OperationName = \"PersonAndFilms\",\n    Variables = new {\n        id = \"cGVvcGxlOjE=\"\n    }\n};\n```\n\n\u003e [!WARNING]\n\u003e Be careful when using `byte[]` in your variables object, as most JSON serializers will treat that as binary data.\n\u003e \n\u003e If you really need to send a *list of bytes* with a `byte[]` as a  source, then convert it to a `List\u003cbyte\u003e` first, which will tell the serializer to output a list of numbers instead of a base64-encoded string.\n\n### Execute Query/Mutation\n\n```csharp\npublic class ResponseType \n{\n    public PersonType Person { get; set; }\n}\n\npublic class PersonType \n{\n    public string Name { get; set; }\n    public FilmConnectionType FilmConnection { get; set; }    \n}\n\npublic class FilmConnectionType {\n    public List\u003cFilmContentType\u003e Films { get; set; }    \n}\n\npublic class FilmContentType {\n    public string Title { get; set; }\n}\n\nvar graphQLResponse = await graphQLClient.SendQueryAsync\u003cResponseType\u003e(personAndFilmsRequest);\n\nvar personName = graphQLResponse.Data.Person.Name;\n```\n\nUsing the extension method for anonymously typed responses (namespace `GraphQL.Client.Abstractions`) you could achieve the same result with the following code:\n\n```csharp\nvar graphQLResponse = await graphQLClient.SendQueryAsync(\n    personAndFilmsRequest, \n    () =\u003e new { person = new PersonType()});\nvar personName = graphQLResponse.Data.person.Name;\n```\n\n\u003e [!IMPORTANT]\n\u003e Note that the field in the GraphQL response which gets deserialized into the response object is the `data` field.\n\u003e\n\u003e A common mistake is to try to directly use the `PersonType` class as response type (because thats the *thing* you actually want to query), but the returned response object contains a property `person` containing a `PersonType` object (like the `ResponseType` modelled above).\n\n### Use Subscriptions\n\n```csharp\npublic class UserJoinedSubscriptionResult {\n    public ChatUser UserJoined { get; set; }\n\n    public class ChatUser {\n        public string DisplayName { get; set; }\n        public string Id { get; set; }\n    }\n}\n```\n\n#### Create subscription\n\n```csharp\nvar userJoinedRequest = new GraphQLRequest {\n    Query = @\"\n    subscription {\n        userJoined{\n            displayName\n            id\n        }\n    }\"\n};\n\nIObservable\u003cGraphQLResponse\u003cUserJoinedSubscriptionResult\u003e\u003e subscriptionStream \n    = client.CreateSubscriptionStream\u003cUserJoinedSubscriptionResult\u003e(userJoinedRequest);\n\nvar subscription = subscriptionStream.Subscribe(response =\u003e \n    {\n        Console.WriteLine($\"user '{response.Data.UserJoined.DisplayName}' joined\")\n    });\n```\n\n#### End Subscription\n\n```csharp\nsubscription.Dispose();\n```\n\n### Automatic persisted queries (APQ)\n\n[Automatic persisted queries (APQ)](https://www.apollographql.com/docs/apollo-server/performance/apq/) are supported since client version 6.1.0.\n\nAPQ can be enabled by configuring `GraphQLHttpClientOptions.EnableAutomaticPersistedQueries` to resolve to `true`.\n\nBy default, the client will automatically disable APQ for the current session if the server responds with a `PersistedQueryNotSupported` error or a 400 or 600 HTTP status code.\nThis can be customized by configuring `GraphQLHttpClientOptions.DisableAPQ`.\n\nTo re-enable APQ after it has been automatically disabled, `GraphQLHttpClient` needs to be disposed an recreated.\n\nAPQ works by first sending a hash of the query string to the server, and only sending the full query string if the server has not yet cached a query with a matching hash.\nWith queries supplied as a string parameter to `GraphQLRequest`, the hash gets computed each time the request is sent.\n\nWhen you want to reuse a query string (propably to leverage APQ :wink:), declare the query using the `GraphQLQuery` class. This way, the hash gets computed once on construction\nof the `GraphQLQuery` object and handed down to each `GraphQLRequest` using the query.\n\n```csharp\nGraphQLQuery query = new(\"\"\"\n                         query PersonAndFilms($id: ID) {\n                             person(id: $id) {\n                                 name\n                                 filmConnection {\n                                     films {\n                                         title\n                                     }\n                                 }\n                             }\n                         }\n                         \"\"\");\n                         \nvar graphQLResponse = await graphQLClient.SendQueryAsync\u003cResponseType\u003e(\n    query, \n    \"PersonAndFilms\",\n    new { id = \"cGVvcGxlOjE=\" });\n```\n\n### Syntax Highlighting for GraphQL strings in IDEs\n\n.NET 7.0 introduced the [StringSyntaxAttribute](https://learn.microsoft.com/en-us/dotnet/api/system.diagnostics.codeanalysis.stringsyntaxattribute?view=net-8.0) to have a unified way of telling what data is expected in a given `string` or `ReadOnlySpan\u003cchar\u003e`. IDEs like Visual Studio and Rider can then use this to provide syntax highlighting and checking.\n\nFrom v6.0.4 on all GraphQL string parameters in this library are decorated with the `[StringSyntax(\"GraphQL\")]` attribute.\n\nCurrently, there is no native support for GraphQL formatting and syntax highlighting in Visual Studio, but the [GraphQLTools Extension](https://marketplace.visualstudio.com/items?itemName=codearchitects-research.GraphQLTools) provides that for you.\n\nFor Rider, JetBrains provides a [Plugin](https://plugins.jetbrains.com/plugin/8097-graphql), too.\n\nTo leverage syntax highlighting in variable declarations, use the `GraphQLQuery` class.\n\n\n## Useful Links\n\n* [StarWars Example Server (GitHub)](https://github.com/graphql/swapi-graphql)\n* [StarWars Example Server (EndPoint)](https://swapi.apis.guru/)\n\n* [GitHub GraphQL API Docs](https://developer.github.com/v4/guides/forming-calls/)\n* [GitHub GraphQL Explorer](https://developer.github.com/v4/explorer/)\n* [GitHub GraphQL Endpoint](https://api.github.com/graphql)\n\n## Blazor WebAssembly Limitations\n\nBlazor 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:\n* [ClientCertificates](https://docs.microsoft.com/en-us/dotnet/api/system.net.websockets.clientwebsocketoptions.clientcertificates?view=netcore-3.1#System_Net_WebSockets_ClientWebSocketOptions_ClientCertificates)\n* [UseDefaultCredentials](https://docs.microsoft.com/en-us/dotnet/api/system.net.websockets.clientwebsocketoptions.usedefaultcredentials?view=netcore-3.1)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgraphql-dotnet%2Fgraphql-client","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgraphql-dotnet%2Fgraphql-client","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgraphql-dotnet%2Fgraphql-client/lists"}