Anything documented here is part of the public API that Flask-Magql provides, unless otherwise indicated. Anything not documented here is considered internal or private and may change at any time.


class flask_magql.MagqlExtension(schema, *, decorators=None)#

Serve a Magql Schema to provide a GraphQL API.

The following views are registered. The blueprint’s name is magql by default, which is the prefix for each endpoint name.






The GraphQL API view. Supports the multipart spec and batched operations.



The GraphQL schema document served as a text file. Useful if a tool does not use the introspection query to discover the API.



The GraphiQL UI for exploring the schema and building queries.

  • schema (magql.Schema) – The schema to serve.

  • decorators (list[t.Callable[[t.Callable[..., ResponseReturnValue]], t.Callable[..., ResponseReturnValue]]] | None) – View decorators applied to each view function. This can be used to apply authentication, CORS, etc.


The Magql schema to serve.

blueprint: Blueprint#

The Flask blueprint that will hold these GraphQL routes and be registered on the app. The blueprint can be modified, for example to add a URL prefix: me.blueprint.url_prefix = "/api".


View decorators to apply to each view function. This can be used to apply authentication, CORS, etc.


Register the GraphQL API on the given Flask app.

Applies decorators to each view function and registers it on blueprint, then registers the blueprint on the app.


app (Flask) – The app to register on.

Return type:



Decorate a function that should be called by execute() to provide a value for info.context in resolvers.


f (Callable[[], Any]) –

Return type:

Callable[[], Any]

execute(source, variables=None, operation=None)#

Execute a GraphQL operation (query or mutation). The SQLAlchemy session is passed as the context.

  • source (str) – The operation (query or mutation) written in GraphQL language to execute on the schema.

  • variables (dict[str, Any] | None) – Maps placeholder names in the source to input values passed along with the request.

  • operation (str | None) – The name of the operation if the source defines multiple.

Return type: