From c73b2b8d34da9356009285c78894eb53299178ab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Valt=C3=BDr=20=C3=96rn=20Kjartansson?= Date: Sun, 23 Dec 2018 13:14:15 +0000 Subject: [PATCH 1/2] Add request and response to GraphQL context This allows the GraphQL resolvers access to things like session, headers etc. Also enables creation of powerful GraphQL middleware. --- responder/ext/graphql.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/responder/ext/graphql.py b/responder/ext/graphql.py index ecd7d6b..806d43e 100644 --- a/responder/ext/graphql.py +++ b/responder/ext/graphql.py @@ -48,8 +48,9 @@ class GraphQLView: return query, variables, operation_name = await self._resolve_graphql_query(req) + context = {"request": req, "response": resp} result = schema.execute( - query, variables=variables, operation_name=operation_name + query, variables=variables, operation_name=operation_name, context=context ) result, status_code = encode_execution_results( [result], From d541aca80f821ce20cd79559111b14d1e1e74c83 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Valt=C3=BDr=20=C3=96rn=20Kjartansson?= Date: Sun, 23 Dec 2018 13:28:50 +0000 Subject: [PATCH 2/2] Mention the GraphQL context object in docs --- docs/source/tour.rst | 2 ++ 1 file changed, 2 insertions(+) diff --git a/docs/source/tour.rst b/docs/source/tour.rst index a331d7d..6ccc367 100644 --- a/docs/source/tour.rst +++ b/docs/source/tour.rst @@ -52,6 +52,8 @@ Serve a GraphQL API:: Visiting the endpoint will render a *GraphiQL* instance, in the browser. +You can make use of Responder's Request and Response objects in your GraphQL resolvers through ``info.context['request']`` and ``info.context['response']``. + OpenAPI Schema Support ----------------------