Skip to main content
FastAPI Docs

Search documentation

Type to search this documentation.

On this pageOverview

GraphQL

As FastAPI is based on the ASGI standard, it's very easy to integrate any GraphQL library also compatible with ASGI.

You can combine normal FastAPI path operations with GraphQL on the same application.

Here are some of the GraphQL libraries that have ASGI support. You could use them with FastAPI:

If you need or want to work with GraphQL, Strawberry is the recommended library as it has the design closest to FastAPI's design, it's all based on type annotations.

Depending on your use case, you might prefer to use a different library, but if you asked me, I would probably suggest you try Strawberry.

Here's a small preview of how you could integrate Strawberry with FastAPI:

Python
import strawberry
from fastapi import FastAPI
from strawberry.fastapi import GraphQLRouter


@strawberry.type
class User:
    name: str
    age: int


@strawberry.type
class Query:
    @strawberry.field
    def user(self) -> User:
        return User(name="Patrick", age=100)


schema = strawberry.Schema(query=Query)


graphql_app = GraphQLRouter(schema)

app = FastAPI()
app.include_router(graphql_app, prefix="/graphql")

You can learn more about Strawberry in the Strawberry documentation.

And also the docs about Strawberry with FastAPI.

Previous versions of Starlette included a GraphQLApp class to integrate with Graphene.

It was deprecated from Starlette, but if you have code that used it, you can easily migrate to starlette-graphene3, that covers the same use case and has an almost identical interface.

You can learn more about GraphQL in the official GraphQL documentation.

You can also read more about each of those libraries described above in their links.

Suggest an edit

Propose a replacement for this page. The site team reviews it before applying any changes.

Export
Documentation menu