ZeroQL
is a compile-time, strongly typed GraphQL client for C#. Instead of
sending raw query strings, you write LINQ-style lambda expressions
that ZeroQL's Roslyn source generator compiles into GraphQL
operations at build time.
Code generation
The schema and client settings are configured in a
*.zeroql.json file in the project that owns the
generated client:
{
"$schema": "https://raw.githubusercontent.com/byme8/ZeroQL/main/schema.verified.json",
"graphql": "path/to/schema.graphql",
"namespace": "JTL.Platform.Graphql",
"clientName": "JTLErpGraphqlService"
}
The ZeroQL CLI tool (pinned in dotnet-tools.json)
generates the JTLErpGraphqlService client class from the
schema. Run it once whenever the schema changes:
dotnet tool restore
zeroql generate --config graphqlapi.zeroql.json
The "not bootstrapped" exception
ZeroQL pre-compiles lambda expressions into a static lookup table
during the build of the assembly that contains the source-generated
client code.
If you write a query lambda in a different assembly — one
that was not compiled by the ZeroQL source generator against the
same schema — ZeroQL cannot find the pre-compiled operation
and throws a ZeroQLNotBootstrappedException at
runtime.
All queries and mutations must therefore reside in the same assembly
that owns the generated JTLErpGraphqlService client
(i.e. the project with the *.zeroql.json config and the
ZeroQL package reference).
Example
// Must live in the assembly compiled by the ZeroQL source generator
var result = await graphqlService.Query(
q => q.GetItemById(
id: "42",
selector: item => new { item.Id, item.ProductGroupId }),
cancellationToken: cancellationToken);
var item = result.Data;