QueryByShape.GraphQLClient
1.0.9-beta
See the version list below for details.
dotnet add package QueryByShape.GraphQLClient --version 1.0.9-beta
NuGet\Install-Package QueryByShape.GraphQLClient -Version 1.0.9-beta
<PackageReference Include="QueryByShape.GraphQLClient" Version="1.0.9-beta" />
<PackageVersion Include="QueryByShape.GraphQLClient" Version="1.0.9-beta" />
<PackageReference Include="QueryByShape.GraphQLClient" />
paket add QueryByShape.GraphQLClient --version 1.0.9-beta
#r "nuget: QueryByShape.GraphQLClient, 1.0.9-beta"
#:package QueryByShape.GraphQLClient@1.0.9-beta
#addin nuget:?package=QueryByShape.GraphQLClient&version=1.0.9-beta&prerelease
#tool nuget:?package=QueryByShape.GraphQLClient&version=1.0.9-beta&prerelease
QueryByShape
QueryByShape autogenerates GraphQL queries at build-time based on the "shape" of your result type. The current / first implementation is an extension to the GraphQL.Client (.NET).
Usage
GraphQLResponse<StarWarsFilms> filmsResponse = await client.SendQueryByAsync<StarWarsFilms>(variables);
StarWarsFilms films = filmsResponse?.Data;
Goals
- Infer / generate a GraphQL Query based on the shape of a result type
- Composing objects vs gql queries
- Performance - generate queries at build time
v1 Features
- Queries
- Variables
- Arguments
- Aliasing
- JsonIgore (System.Text.Json)
- JsonPropertyName (System.Text.Json)
- Default Variables
- Interfaces
- API Documentation
- Unions (possibly v1.5)
Limitations
- Requires .NET 8 or higher
- Only supports System.Text.Json / GraphQL.Client.Serializer.SystemTextJson
- Queries must be partial
- Queries must define variables / arguments ahead of time
- Dictionaries are not supprted
Installation
This project is currently in beta you will need to enable prerelease packages in UI or cli
dotnet add package QueryByShape.GraphQLClient --prerelease
Example Queries
All samples are written for the Star Wars GraphQL API
<table> <tr> <td> Query Options - C# </td> </tr> <tr> <td>
using QueryByShape;
namespace StarWars
{
// Fields are excluded by default
[Query(OperationName="SimpleIsh", IncludeFields=true)]
public partial class SimpleQuery : IGeneratedQuery
{
public CountModel AllPeople { get; set; }
}
public class CountModel
{
public int TotalCount;
}
}
</td> </tr> <tr> <td> GraphQL Output </td> </tr> <tr> <td valign="top">
query SimpleIsh {
allPeople {
totalCount
}
}
</td> </tr> </table>
<table> <tr> <td> Variables and Arguments - C# </td> </tr> <tr> <td>
using QueryByShape;
using System.Collections.Generic;
namespace StarWars
{
[Query]
[Variable("$id", "ID!")]
public partial class VariablesAndArgumentsQuery : IGeneratedQuery
{
[Argument("id", "$id")]
public PersonModel Person { get; set; }
}
public class PersonModel
{
public string Id { get; set; }
public string Name { get; set; }
public HomeworldNameModel Homeworld { get; set; }
}
public class HomeworldNameModel
{
public string Name { get; set; }
}
}
</td> </tr> <tr> <td> GraphQL Output </td> </tr> <tr>
<td valign="top">
query VariablesAndArgumentsQuery($id: ID!) {
person (id: $id) {
id
name
homeworld {
name
}
}
}
</td> </tr> </table>
<table> <tr> <td> Aliasing - C# </td> </tr> <tr> <td>
using QueryByShape;
using System.Collections.Generic;
namespace StarWars
{
[Query]
[Variable("$newHopeId", "ID!")]
[Variable("$empireId", "ID!")]
public partial class AliasQuery : IGeneratedQuery
{
[Argument("id", "$newHopeId")]
[AliasOf("film")]
public FilmDirectorModel NewHope { get; set; }
[Argument("id", "$empireId")]
[AliasOf("film")]
public FilmDirectorModel Empire { get; set; }
}
public class FilmDirectorModel
{
public string Director { get; set; }
}
}
</td> </tr> <tr> <td> GraphQL Output </td> </tr> <tr>
<td valign="top">
query ExampleQuery ($newHopeId: ID!, $empireId: ID!) {
newHope: film (id: $newHopeId ) {
director
}
empire: film (id: $empireId ) {
director
}
}
</td> </tr> </table>
<table> <tr> <td> Supported System.Text.Json Attributes - C# </td> </tr> <tr> <td>
using QueryByShape;
using System.Collections.Generic;
using System.Text.Json.Serialization;
namespace StarWars
{
[Query]
[Variable("$id", "ID!")]
public partial class SystemTextJsonAttributesQuery : IGeneratedQuery
{
[Argument("id", "$id")]
public PersonHeightModel Person { get; set; }
}
public class PersonHeightModel
{
public string Id { get; set; }
[JsonIgnore]
public Guid TempId { get; set; }
[JsonPropertyName("name")]
public string PersonName { get; set; }
public int Height { get; set; }
}
}
</td> </tr> <tr> <td> GraphQL Output </td> </tr> <tr>
<td valign="top">
query SystemTextJsonAttributes($id: ID!) {
person (id: $id) {
id
name
height
}
}
</td> </tr> </table>
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
-
net8.0
- GraphQL.Client.Abstractions (>= 6.1.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last Updated |
---|---|---|
1.0.15 | 136 | 3/16/2025 |
1.0.14-beta | 92 | 11/9/2024 |
1.0.13-beta | 84 | 11/4/2024 |
1.0.12-beta | 118 | 10/18/2024 |
1.0.11-beta | 87 | 10/4/2024 |
1.0.10-beta | 113 | 9/18/2024 |
1.0.9-beta | 86 | 9/18/2024 |