Other technologies
Ariadne can be used to add GraphQL server to projects developed using any web framework that supports JSON responses.
Implementation details differ between frameworks, but same steps apply for most of them:
- Use
make_executable_schema
to create executable schema instance. - Create view, route or controller (semantics vary between frameworks) that accepts
GET
andPOST
requests. - If request was made with
GET
method, return response containing GraphQL Playground's HTML. - If request was made with
POST
, disable any CSRF checks, test that its content type isapplication/json
then parse its content as JSON. Return400 BAD REQUEST
if this fails. - Call
graphql_sync
with schema, parsed JSON and any other options that are fit for your implementation. graphql_sync
returns tuple that has two values:boolean
anddict
. Use dict as data for JSON response, and boolean for status code. If boolean istrue
, set response's status code to200
, otherwise it should be400
See the Flask integration for implementation of this algorithm using Flask framework.
Asynchronous servers
If your server stack supports ASGI, you can use graphql
to execute GraphQL queries asynchronously and subscribe
for websocket connections initialized by subscriptions.