ulo
ulo
Documentation

Start here

Coming from NestJSNestJS topics, mapped

The model

Protocols

GraphQLGraphQL over HTTPSubscriptionsEngines

Integrations

Operating

Reference

GraphQL

Engines

What async-graphql and juniper share under the Engine trait, and the places they differ.

An engine adapter implements ulo_graphql::Engine for a schema and a context type, and is bound under the key dyn Engine. Everything that uses it, the endpoint, the gateway and the playground, is the same for both.

ulo-graphql-async-graphqlulo-graphql-juniper
Libraryasync-graphql 7juniper 0.16
AdapterAsyncGraphql<Schema<Q, M, Sub>, Context>Juniper<Q, M, Sub>
Rust floor1.89the workspace's 1.88
Context typeA parameter of the adapter, inserted into the request as Dep<Context>Q::Context, the type the schema's root types name
Reading a provider in a resolverulo_graphql_async_graphql::dep::<T>(ctx)ulo_graphql_juniper::dep::<T>(&context)
PlaygroundGraphiQLjuniper's graphiql_source
Wrong-typed variableAn executed result whose error carries the field's pathA request error with no data

async-graphql

The context is a type parameter of the adapter, because async-graphql accepts any D as request data and the adapter cannot know the application's type by convention. Per call the adapter resolves the context in the call's execution, inserts it as Dep<Context>, and inserts the call's ExecutionRef as a second value that dep reads. A resolver reads the context with ctx.data::<Dep<Context>>()?. The bound schema is a provider like any other, here built by a with factory:

examples/31-graphql/src/lib.rs
with = || -> Api { Schema::new(Query, Mutation, EmptySubscription) },
AsyncGraphql<Api, Gql> as dyn Engine,

examples/31-graphql and examples/32-graphql-subscriptions both use this engine.

juniper

juniper's Context is a type the schema's root types name, so Juniper<Q, M, Sub> resolves Q::Context in the call's execution and hands it to juniper as the context. The context is an execution-scoped provider, as with async-graphql. dep reads through the context's ExecutionRef, so the context type implements AsRef<ExecutionRef>.

The crate's tests bind the pieces directly, the schema as a value and the context and the engine as providers:

crates/ulo-graphql-juniper/tests/engine.rs
fn register(&self, m: &mut ModuleDef<'_>) {
    m.value(schema());
    m.provide::<Ctx>();
    m.provide::<Juniper<Query, Mutation, Subscriptions>>().also_as::<dyn Engine>(|engine| engine);
}

Subscriptions are built on juniper's resolve_into_stream, and a query or mutation sent to subscribe answers one response. No example in examples/ uses juniper.

Where the two disagree

A required variable that is absent or null is a request error in both engines, answered before any field runs. A variable of the wrong type, an Int given a string, is not the same:

  • async-graphql coerces a variable when the field reading it resolves. The request executes and the response is an executed result, 200, whose error carries the path of that field.
  • juniper answers a request error with no data, 422.

A client that branches on a request error sees the fault from juniper only. The difference is async-graphql's, and the adapter does not close it.

How a request error is classified for the HTTP status also differs in detail. async-graphql's adapter names Syntax, Operation, Coercion and Validation. juniper's maps parse errors to Syntax, validation errors to Validation and the operation errors to Operation, and reports a missing required variable as Validation because juniper raises it as one. The HTTP binding answers 422 for Validation and Coercion alike.

A context that fails to build

Neither adapter declares the context as a dependency, because declaring it would make the engine itself execution-scoped. The binding is read at each call. A context that is not bound fails each call with a request error and an error log line, and the HTTP binding answers 500.

Subscriptions

Serve GraphQL subscriptions over graphql-transport-ws beside the HTTP endpoint.

Database

A database is a module that reads its options from configuration, connects under a bound, contributes a health check and closes with the application.

On this page

async-graphqljuniperWhere the two disagreeA context that fails to build