An open API service indexing awesome lists of open source software.

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

Awesome Lists containing this project

README

          

# GraphQL Client Extensions

![logo](https://raw.githubusercontent.com/charlesdevandiere/graphql-client-extensions/master/logo.png)

Extensions for [GraphQL.Client](https://github.com/graphql-dotnet/graphql-client) to build graphQL queries from a C# model.

[![Build Status](https://dev.azure.com/charlesdevandiere/charlesdevandiere/_apis/build/status/charlesdevandiere.graphql-client-extensions?branchName=master)](https://dev.azure.com/charlesdevandiere/charlesdevandiere/_build/latest?definitionId=1&branchName=master)
![Azure DevOps coverage (branch)](https://img.shields.io/azure-devops/coverage/charlesdevandiere/charlesdevandiere/1/master)
[![Nuget](https://img.shields.io/nuget/v/GraphQL.Client.Extensions.svg?color=blue&logo=nuget)](https://www.nuget.org/packages/GraphQL.Client.Extensions)
[![Downloads](https://img.shields.io/nuget/dt/GraphQL.Client.Extensions.svg?logo=nuget)](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)