swadhinbiswas πŸš€ release: 2.0.8 β€” write-path fix (ADR-080), fork-safe GIL pool (ADR-081), HTTP/3 (ADR-082), Security DI fix, docs honesty pass Β· 8/6/2026
731fffe
96 lines Β· 2.1 KB
Raw Download

title: GraphQL Integration
description: Set up Strawberry GraphQL alongside REST endpoints in a JustAPI application.
keywords: [JustAPI, GraphQL, Strawberry, REST, multi-protocol]

JustAPI supports running GraphQL alongside REST endpoints in the same application.

Basic Setup

Install Strawberry:

pip install strawberry-graphql

Create your GraphQL schema:

import strawberry
from justapi import JustAPIApp

@strawberry.type
class User:
    id: int
    name: str
    email: str

@strawberry.type
class Query:
    @strawberry.field
    def users(self) -> list[User]:
        return [User(id=1, name="Alice", email="[email protected]")]

@strawberry.type
class Mutation:
    @strawberry.mutation
    def create_user(self, name: str, email: str) -> User:
        return User(id=2, name=name, email=email)

Mount the GraphQL endpoint in your JustAPI app:

import strawberry
from strawberry.fastapi import GraphQLRouter

app = JustAPIApp()

schema = strawberry.Schema(query=Query, mutation=Mutation)
graphql_app = GraphQLRouter(schema)

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

Testing GraphQL

Start your app and visit http://localhost:8000/graphql for the GraphiQL interactive explorer.

query {
  users {
    id
    name
    email
  }
}

Shared Authentication

JustAPI supports global dependencies that apply to all routes including GraphQL:

from justapi import Depends

def get_current_user(request):
    token = request.headers.get("Authorization", "").replace("Bearer ", "")
    # validate token...
    return {"user_id": 1, "name": "Alice"}

app = JustAPIApp(dependencies=[Depends(get_current_user)])

Recap

  • Install strawberry-graphql for GraphQL support.
  • Mount GraphQLRouter with a prefix using app.include_router().
  • GraphQL runs alongside REST β€” no separate server needed.
  • Use JustAPI's dependency injection for shared auth.

See Also