https://github.com/charlesdevandiere/graphql-client-extensions
Extensions for GraphQL.Client to build graphQL queries from a C# model
https://github.com/charlesdevandiere/graphql-client-extensions
client graphql netstandard
Last synced: 9 months ago
JSON representation
Extensions for GraphQL.Client to build graphQL queries from a C# model
- Host: GitHub
- URL: https://github.com/charlesdevandiere/graphql-client-extensions
- Owner: charlesdevandiere
- License: mit
- Created: 2019-03-01T19:48:38.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2022-12-08T14:54:23.000Z (over 3 years ago)
- Last Synced: 2025-08-01T02:34:52.819Z (11 months ago)
- Topics: client, graphql, netstandard
- Language: C#
- Homepage: https://charlesdevandiere.github.io/graphql-client-extensions/
- Size: 156 KB
- Stars: 5
- Watchers: 2
- Forks: 1
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# GraphQL Client Extensions

Extensions for [GraphQL.Client](https://github.com/graphql-dotnet/graphql-client) to build graphQL queries from a C# model.
[](https://dev.azure.com/charlesdevandiere/charlesdevandiere/_build/latest?definitionId=1&branchName=master)

[](https://www.nuget.org/packages/GraphQL.Client.Extensions)
[](https://www.nuget.org/packages/GraphQL.Client.Extensions)
Uses [GraphQL.Query.Builder](https://github.com/charlesdevandiere/graphql-query-builder-dotnet) for query building.
See complete documentation [here](https://charlesdevandiere.github.io/graphql-client-extensions/)
See sample [here](https://github.com/charlesdevandiere/graphql-client-extensions/tree/master/sample/Pokedex)
## Install
```console
dotnet add package GraphQL.Client.Extensions
```
## Usage
```csharp
// create the query with GraphQL.Query.Builder
Query query = new Query("humans", options) // set the name of the query
.AddArguments(new { id = "uE78f5hq" }) // add query arguments
.AddField(h => h.FirstName) // add firstName field
.AddField(h => h.LastName) // add lastName field
.AddField( // add a sub-object field
h => h.HomePlanet, // set the name of the field
sq => sq /// build the sub-query
.AddField(p => p.Name)
)
.AddField( // add a sub-list field
h => h.Friends,
sq => sq
.AddField(f => f.FirstName)
.AddField(f => f.LastName)
);
// this corresponds to :
// humans (id: "uE78f5hq") {
// FirstName
// LastName
// HomePlanet {
// Name
// }
// Friends {
// FirstName
// LastName
// }
// }
using (GraphQLClient client = new(""))
{
// run the query
Human human = await client.Get(query);
}
```
## Dependencies
- [GraphQL.Client](https://www.nuget.org/packages/GraphQL.Client/) (>= 1.0.3)
- [GraphQL.Query.Builder](https://www.nuget.org/packages/GraphQL.Query.Builder/) (>= 2.0.0)
- [GraphQL.Query.Builder.Formatter.NewtonsoftJson](https://www.nuget.org/packages/GraphQL.Query.Builder.Formatter.NewtonsoftJson/) (>= 1.0.0)