Simple GraphQL client wrapper for .NET.
The packages are available at nuget.org for installation (see karrocon.GraphQlClient and karrocon.GraphQlClient.Relay).
Supports query string building in an expression-based style:
var queryString = GraphQueryStringBuilder.Build<QueryRoot>(queryBuilder => queryBuilder
.AddObjectAs<IEnumerable<Shop>, Shop>(query => query.Shops, shopBuilder => shopBuilder
.AddScalar(shop => shop.Name)
.AddObjectAs<IEnumerable<User>, User>(shop => shop.Users, userBuilder => userBuilder
.IncludeAllScalars()
.AddObjectAs<IEnumerable<Address>,Address>(user => user.Addresses, addressBuilder => addressBuilder
.IncludeAllScalars()
)
.AddArgument("age", 18)
)
.AddArgumentAsVariable("name", "nameVariable")
)
);
It also supports building query strings for Relay-based servers:
var queryString = GraphQueryStringBuilder.Build<QueryRoot>(queryBuilder => queryBuilder
.AddConnection(query => query.Shops, 10, shopBuilder => shopBuilder
.AddScalar(shop => shop.Name)
.AddConnection(shop => shop.Users, 5, userBuilder => userBuilder
.IncludeAllScalars()
.AddConnection(user => user.Addresses, 1, addressBuilder => addressBuilder
.IncludeAllScalars()
)
)
)
);
The library features an extension method for graphql-dotnet.IGraphQlClient to query every Relay page at once:
var queryString = GraphQueryStringBuilder.Build<QueryRoot>(queryBuilder => queryBuilder
.AddConnection(query => query.Shops, 10, shopBuilder => shopBuilder
.AddScalar(shop => shop.Name)
.AddConnection(shop => shop.Users, 5, userBuilder => userBuilder
.IncludeAllScalars()
.AddConnection(user => user.Addresses, 1, addressBuilder => addressBuilder
.IncludeAllScalars()
)
)
)
);
var result = await client.QueryAllPagesAsync(new GraphQlRequest { Query = queryString });