Cloud Parts

GraphQL libraries

An engine that parses, validates and executes GraphQL queries, plus a schema library on top that defines types and resolvers either as SDL text or as code.

How they work

Every GraphQL server runs the same steps from the specification: parse the query into a syntax tree, validate it against the schema, then execute it by calling one resolver per requested field. In Python that engine is graphql-core, a port of the JavaScript reference implementation GraphQL.js that follows it closely: version 3.3.0 matches GraphQL.js 17.0.2. You rarely build the engine’s schema objects by hand, because a schema library does it for you.

Schema-first libraries start from SDL. In Ariadne the schema is a string, you attach resolver functions to its fields with objects such as QueryType, and make_executable_schema joins the two. Code-first libraries generate the schema from code: Strawberry reads type hints on classes decorated with @strawberry.type, and Graphene uses ObjectType subclasses with resolve_ methods. Strawberry, Ariadne and Graphene 3 all run on graphql-core 3, so they parse, validate and execute queries the same way and differ in how you write the schema.

They plug into a web framework as one route. Strawberry’s GraphQLRouter is a FastAPI router, Ariadne’s GraphQL is an ASGI app that FastAPI mounts, and Graphene 3 uses the starlette-graphene3 package. Resolvers that load related data one row at a time cause N+1 queries, so libraries such as Strawberry ship a DataLoader that batches and caches those lookups.

Technologies

What all api frameworks have in common →

Sources

Improve this page on GitHub