Typed GraphQL

Fóir generates a GraphQL schema from your models, with typed queries, mutations and inputs for each one. A CLI check tells your build when the types you committed no longer match the project.

What each model generates

Each model that holds records produces a singular query, a plural query that returns a cursor-paginated connection, mutations to create, update and delete, and typed filter, ordering and update inputs. Models with publishing on get publish and unpublish mutations as well. Your fields sit at the top level of the record type, beside system fields that start with an underscore.

When the production schema changes

The schema is served in two channels, draft and published. Editing a model changes the draft, and production keys keep the published schema until a release carries the change. A brand-new model or operation is released as it is created, as is a model update that only adds optional fields. After a release, the public schema changes for every consumer within seconds.

The build-time check

foir types generates TypeScript types and the typed client's selections from the project. With --check it writes nothing and exits non-zero when the committed file differs from a fresh generation. Run in CI, that fails the build when the project has changed and your committed types have not. Types are generated per API key, so an operation the key cannot perform is absent, and calling it is a compile error.

The runtime check

The generated client warns once per client instance when the server's schema has moved since generation. It throws FoirSchemaDriftError on a typed call that depends on something no longer served, such as a removed field or argument.

Where the typing stops

In the generated types, ordering is a closed, checked type. Filters are typed as unknown, and so are the arguments and results of namespace operations. Hand-written GraphQL can be typed with graphql-codegen against the schema, as a build step you own.

Read the detail

The GraphQL guide lists the queries, mutations and inputs generated for a model and where to explore the schema.