Django / Ariadne Server¶
GraphLink generates a server that lives inside a Django project: a GraphQL view and the @glRest* operations are
plain async Django views that receive the Django HttpRequest, so your middleware, sessions and request.user
apply. The services, models, resolvers, loaders and guards are the same as in the
FastAPI / Ariadne target. Services are async, so run the project under an ASGI server such as
uvicorn.
Server mode config¶
{
"schemaPaths": ["schema/*.graphql"],
"mode": "server",
"outputDir": "generated",
"serverConfig": {
"djangoAriadne": {
"graphqlPath": "/graphql",
"generateEntryPoint": true,
"injectContext": false,
"useResolveInfo": false
}
}
}
The options are the ones of fastapiAriadne. Install django, ariadne, uvicorn, pydantic and starlette
(Ariadne's WebSocket handler uses it); keep graphql-core below 3.2.14. A schema with only GraphQL operations,
only @glRest* operations, or both is supported: only the matching routes are generated.
Wiring¶
from generated.app import create_urlpatterns
from services import services # your GraphLinkServices(...)
urlpatterns = create_urlpatterns(services)
from django.core.asgi import get_asgi_application
from generated.app import create_app
from services import services
application = create_app(services, get_asgi_application())
create_urlpatterns returns the GraphQL view (queries, mutations, multipart uploads) and one CSRF-exempt async
re_path per REST route. create_app is only needed for subscriptions: Django cannot serve WebSockets, so it
wraps your ASGI application, hands the GraphQL WebSocket path to Ariadne and answers lifespan. If you serve
subscriptions with Django Channels instead, skip create_app.
Request, context and middleware¶
context.requestis the DjangoHttpRequestfor queries, mutations and REST, so acontext_factorycan readrequest.user(useawait request.auser()in async code). Subscriptions get the Starlette WebSocket.- CORS is not generated: add
django-cors-headersor your own middleware. - Django's body limits apply (
DATA_UPLOAD_MAX_MEMORY_SIZEcaps JSON GraphQL bodies; the REST layer caps JSON and form bodies at 100 KB, files at 100 MB). - Django reads a request body completely before the view runs, so uploads are spooled to disk first and are not streamed from the socket.
Everything else (batch mappings, guards, interceptors, depth limit, uploads) works as described in FastAPI / Ariadne.