Closed simonw closed 4 years ago
https://graphql.org/learn/serving-over-http/#http-methods-headers-and-body
Your GraphQL HTTP server should handle the HTTP GET and POST methods.
GET request
When receiving an HTTP GET request, the GraphQL query should be specified in the "query" query string. For example, if we wanted to execute the following GraphQL query:
{ me { name } }
This request could be sent via an HTTP GET like so:
http://myapi/graphql?query={me{name}}
Query variables can be sent as a JSON-encoded string in an additional query parameter called
variables
. If the query contains several named operations, anoperationName
query parameter can be used to control which one should be executed.
I'm serving GraphiQL from on GET to /graphql
at the moment if there is now POST body.
To support GET I can change this logic to include a check to see if ?query=
was passed.
I'm going to imitate Starlette here: they do this:
if request.method in ("GET", "HEAD"):
if "text/html" in request.headers.get("Accept", ""):
if not self.graphiql:
return PlainTextResponse(
"Not Found", status_code=status.HTTP_404_NOT_FOUND
)
return await self.handle_graphiql(request)
Where handle_graphiql(request)
returns the GraphiQL interface.
One difference: I'm going to set Vary: accept
on the GraphiQL response to ensure things can be cached correctly.
GraphiQL desktop app provides this as an option.