Skip to content

Commit c3b775f

Browse files
authored
Merge branch 'master' into gather-async-execution-results
2 parents 2bfa6ef + 1972b27 commit c3b775f

File tree

15 files changed

+126
-15
lines changed

15 files changed

+126
-15
lines changed

docs/aiohttp.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,14 +52,14 @@ gql_view(request) # <-- the instance is callable and expects a `aiohttp.web.Req
5252
* `root_value`: The `root_value` you want to provide to graphql `execute`.
5353
* `pretty`: Whether or not you want the response to be pretty printed JSON.
5454
* `graphiql`: If `True`, may present [GraphiQL](https://github.com/graphql/graphiql) when loaded directly from a browser (a useful tool for debugging and exploration).
55-
* `graphiql_version`: The graphiql version to load. Defaults to **"1.0.3"**.
55+
* `graphiql_version`: The graphiql version to load. Defaults to **"1.4.7"**.
5656
* `graphiql_template`: Inject a Jinja template string to customize GraphiQL.
5757
* `graphiql_html_title`: The graphiql title to display. Defaults to **"GraphiQL"**.
58-
* `jinja_env`: Sets jinja environment to be used to process GraphiQL template. If Jinja’s async mode is enabled (by `enable_async=True`), uses
59-
`Template.render_async` instead of `Template.render`. If environment is not set, fallbacks to simple regex-based renderer.
58+
* `jinja_env`: Sets jinja environment to be used to process GraphiQL template. If Jinja’s async mode is enabled (by `enable_async=True`), uses `Template.render_async` instead of `Template.render`. If environment is not set, fallbacks to simple regex-based renderer.
6059
* `batch`: Set the GraphQL view as batch (for using in [Apollo-Client](http://dev.apollodata.com/core/network.html#query-batching) or [ReactRelayNetworkLayer](https://github.com/nodkz/react-relay-network-layer))
6160
* `middleware`: A list of graphql [middlewares](http://docs.graphene-python.org/en/latest/execution/middleware/).
6261
* `validation_rules`: A list of graphql validation rules.
62+
* `execution_context_class`: Specifies a custom execution context class.
6363
* `max_age`: Sets the response header Access-Control-Max-Age for preflight requests.
6464
* `encode`: the encoder to use for responses (sensibly defaults to `graphql_server.json_encode`).
6565
* `format_error`: the error formatter to use for responses (sensibly defaults to `graphql_server.default_format_error`.

docs/flask.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,12 +53,13 @@ More info at [Graphene v3 release notes](https://github.com/graphql-python/graph
5353
* `root_value`: The `root_value` you want to provide to graphql `execute`.
5454
* `pretty`: Whether or not you want the response to be pretty printed JSON.
5555
* `graphiql`: If `True`, may present [GraphiQL](https://github.com/graphql/graphiql) when loaded directly from a browser (a useful tool for debugging and exploration).
56-
* `graphiql_version`: The graphiql version to load. Defaults to **"1.0.3"**.
56+
* `graphiql_version`: The graphiql version to load. Defaults to **"1.4.7"**.
5757
* `graphiql_template`: Inject a Jinja template string to customize GraphiQL.
5858
* `graphiql_html_title`: The graphiql title to display. Defaults to **"GraphiQL"**.
5959
* `batch`: Set the GraphQL view as batch (for using in [Apollo-Client](http://dev.apollodata.com/core/network.html#query-batching) or [ReactRelayNetworkLayer](https://github.com/nodkz/react-relay-network-layer))
6060
* `middleware`: A list of graphql [middlewares](http://docs.graphene-python.org/en/latest/execution/middleware/).
61-
* `validation_rules`: A list of graphql validation rules.
61+
* `validation_rules`: A list of graphql validation rules.
62+
* `execution_context_class`: Specifies a custom execution context class.
6263
* `encode`: the encoder to use for responses (sensibly defaults to `graphql_server.json_encode`).
6364
* `format_error`: the error formatter to use for responses (sensibly defaults to `graphql_server.default_format_error`.
6465
* `subscriptions`: The GraphiQL socket endpoint for using subscriptions in graphql-ws.
@@ -79,4 +80,4 @@ class UserRootValue(GraphQLView):
7980
```
8081

8182
## Contributing
82-
See [CONTRIBUTING.md](../CONTRIBUTING.md)
83+
See [CONTRIBUTING.md](../CONTRIBUTING.md)

docs/sanic.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,14 +44,14 @@ This will add `/graphql` endpoint to your app and enable the GraphiQL IDE.
4444
* `root_value`: The `root_value` you want to provide to graphql `execute`.
4545
* `pretty`: Whether or not you want the response to be pretty printed JSON.
4646
* `graphiql`: If `True`, may present [GraphiQL](https://github.com/graphql/graphiql) when loaded directly from a browser (a useful tool for debugging and exploration).
47-
* `graphiql_version`: The graphiql version to load. Defaults to **"1.0.3"**.
47+
* `graphiql_version`: The graphiql version to load. Defaults to **"1.4.7"**.
4848
* `graphiql_template`: Inject a Jinja template string to customize GraphiQL.
4949
* `graphiql_html_title`: The graphiql title to display. Defaults to **"GraphiQL"**.
50-
* `jinja_env`: Sets jinja environment to be used to process GraphiQL template. If Jinja’s async mode is enabled (by `enable_async=True`), uses
51-
`Template.render_async` instead of `Template.render`. If environment is not set, fallbacks to simple regex-based renderer.
50+
* `jinja_env`: Sets jinja environment to be used to process GraphiQL template. If Jinja’s async mode is enabled (by `enable_async=True`), uses `Template.render_async` instead of `Template.render`. If environment is not set, fallbacks to simple regex-based renderer.
5251
* `batch`: Set the GraphQL view as batch (for using in [Apollo-Client](http://dev.apollodata.com/core/network.html#query-batching) or [ReactRelayNetworkLayer](https://github.com/nodkz/react-relay-network-layer))
5352
* `middleware`: A list of graphql [middlewares](http://docs.graphene-python.org/en/latest/execution/middleware/).
54-
* `validation_rules`: A list of graphql validation rules.
53+
* `validation_rules`: A list of graphql validation rules.
54+
* `execution_context_class`: Specifies a custom execution context class.
5555
* `max_age`: Sets the response header Access-Control-Max-Age for preflight requests.
5656
* `encode`: the encoder to use for responses (sensibly defaults to `graphql_server.json_encode`).
5757
* `format_error`: the error formatter to use for responses (sensibly defaults to `graphql_server.default_format_error`.
@@ -72,4 +72,4 @@ class UserRootValue(GraphQLView):
7272
```
7373

7474
## Contributing
75-
See [CONTRIBUTING.md](../CONTRIBUTING.md)
75+
See [CONTRIBUTING.md](../CONTRIBUTING.md)

docs/webob.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,12 +43,13 @@ This will add `/graphql` endpoint to your app and enable the GraphiQL IDE.
4343
* `root_value`: The `root_value` you want to provide to graphql `execute`.
4444
* `pretty`: Whether or not you want the response to be pretty printed JSON.
4545
* `graphiql`: If `True`, may present [GraphiQL](https://github.com/graphql/graphiql) when loaded directly from a browser (a useful tool for debugging and exploration).
46-
* `graphiql_version`: The graphiql version to load. Defaults to **"1.0.3"**.
46+
* `graphiql_version`: The graphiql version to load. Defaults to **"1.4.7"**.
4747
* `graphiql_template`: Inject a Jinja template string to customize GraphiQL.
4848
* `graphiql_html_title`: The graphiql title to display. Defaults to **"GraphiQL"**.
4949
* `batch`: Set the GraphQL view as batch (for using in [Apollo-Client](http://dev.apollodata.com/core/network.html#query-batching) or [ReactRelayNetworkLayer](https://github.com/nodkz/react-relay-network-layer))
5050
* `middleware`: A list of graphql [middlewares](http://docs.graphene-python.org/en/latest/execution/middleware/).
51-
* `validation_rules`: A list of graphql validation rules.
51+
* `validation_rules`: A list of graphql validation rules.
52+
* `execution_context_class`: Specifies a custom execution context class.
5253
* `encode`: the encoder to use for responses (sensibly defaults to `graphql_server.json_encode`).
5354
* `format_error`: the error formatter to use for responses (sensibly defaults to `graphql_server.default_format_error`.
5455
* `enable_async`: whether `async` mode will be enabled.
@@ -59,4 +60,4 @@ This will add `/graphql` endpoint to your app and enable the GraphiQL IDE.
5960
* `should_persist_headers`: An optional boolean which enables to persist headers to storage when true. Defaults to **false**.
6061

6162
## Contributing
62-
See [CONTRIBUTING.md](../CONTRIBUTING.md)
63+
See [CONTRIBUTING.md](../CONTRIBUTING.md)

graphql_server/aiohttp/graphqlview.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ class GraphQLView:
3838
graphiql_html_title = None
3939
middleware = None
4040
validation_rules = None
41+
execution_context_class = None
4142
batch = False
4243
jinja_env = None
4344
max_age = 86400
@@ -86,6 +87,9 @@ def get_validation_rules(self):
8687
return specified_rules
8788
return self.validation_rules
8889

90+
def get_execution_context_class(self):
91+
return self.execution_context_class
92+
8993
@staticmethod
9094
async def parse_body(request):
9195
content_type = request.content_type
@@ -161,6 +165,7 @@ async def __call__(self, request):
161165
context_value=self.get_context(request),
162166
middleware=self.get_middleware(),
163167
validation_rules=self.get_validation_rules(),
168+
execution_context_class=self.get_execution_context_class(),
164169
)
165170

166171
exec_res = (

graphql_server/flask/graphqlview.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ class GraphQLView(View):
3737
graphiql_html_title = None
3838
middleware = None
3939
validation_rules = None
40+
execution_context_class = None
4041
batch = False
4142
subscriptions = None
4243
headers = None
@@ -82,6 +83,9 @@ def get_validation_rules(self):
8283
return specified_rules
8384
return self.validation_rules
8485

86+
def get_execution_context_class(self):
87+
return self.execution_context_class
88+
8589
def dispatch_request(self):
8690
try:
8791
request_method = request.method.lower()
@@ -105,6 +109,7 @@ def dispatch_request(self):
105109
context_value=self.get_context(),
106110
middleware=self.get_middleware(),
107111
validation_rules=self.get_validation_rules(),
112+
execution_context_class=self.get_execution_context_class(),
108113
)
109114
result, status_code = encode_execution_results(
110115
execution_results,

graphql_server/quart/graphqlview.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ class GraphQLView(View):
4040
graphiql_html_title = None
4141
middleware = None
4242
validation_rules = None
43+
execution_context_class = None
4344
batch = False
4445
enable_async = False
4546
subscriptions = None
@@ -86,6 +87,9 @@ def get_validation_rules(self):
8687
return specified_rules
8788
return self.validation_rules
8889

90+
def get_execution_context_class(self):
91+
return self.execution_context_class
92+
8993
async def dispatch_request(self):
9094
try:
9195
request_method = request.method.lower()
@@ -109,6 +113,7 @@ async def dispatch_request(self):
109113
context_value=self.get_context(),
110114
middleware=self.get_middleware(),
111115
validation_rules=self.get_validation_rules(),
116+
execution_context_class=self.get_execution_context_class(),
112117
)
113118
exec_res = (
114119
await asyncio.gather(

graphql_server/sanic/graphqlview.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ class GraphQLView(HTTPMethodView):
4040
graphiql_html_title = None
4141
middleware = None
4242
validation_rules = None
43+
execution_context_class = None
4344
batch = False
4445
jinja_env = None
4546
max_age = 86400
@@ -88,6 +89,9 @@ def get_validation_rules(self):
8889
return specified_rules
8990
return self.validation_rules
9091

92+
def get_execution_context_class(self):
93+
return self.execution_context_class
94+
9195
async def __handle_request(self, request, *args, **kwargs):
9296
try:
9397
request_method = request.method.lower()
@@ -115,6 +119,7 @@ async def __handle_request(self, request, *args, **kwargs):
115119
context_value=self.get_context(request),
116120
middleware=self.get_middleware(),
117121
validation_rules=self.get_validation_rules(),
122+
execution_context_class=self.get_execution_context_class(),
118123
)
119124
exec_res = (
120125
await asyncio.gather(

graphql_server/webob/graphqlview.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ class GraphQLView:
3636
graphiql_html_title = None
3737
middleware = None
3838
validation_rules = None
39+
execution_context_class = None
3940
batch = False
4041
enable_async = False
4142
subscriptions = None
@@ -81,6 +82,9 @@ def get_validation_rules(self):
8182
return specified_rules
8283
return self.validation_rules
8384

85+
def get_execution_context_class(self):
86+
return self.execution_context_class
87+
8488
def dispatch_request(self, request):
8589
try:
8690
request_method = request.method.lower()
@@ -107,6 +111,7 @@ def dispatch_request(self, request):
107111
context_value=self.get_context(request),
108112
middleware=self.get_middleware(),
109113
validation_rules=self.get_validation_rules(),
114+
execution_context_class=self.get_execution_context_class(),
110115
)
111116
result, status_code = encode_execution_results(
112117
execution_results,

tests/aiohttp/test_graphqlview.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
from aiohttp import FormData
77
from aiohttp.test_utils import TestClient, TestServer
88

9+
from ..utils import RepeatExecutionContext
910
from .app import create_app, url_string
1011
from .schema import AsyncSchema
1112

@@ -682,3 +683,18 @@ async def test_preflight_incorrect_request(client):
682683
)
683684

684685
assert response.status == 400
686+
687+
688+
@pytest.mark.asyncio
689+
@pytest.mark.parametrize(
690+
"app", [create_app(execution_context_class=RepeatExecutionContext)]
691+
)
692+
async def test_custom_execution_context_class(client):
693+
response = await client.post(
694+
"/graphql",
695+
data=json.dumps(dict(query="{test}")),
696+
headers={"content-type": "application/json"},
697+
)
698+
699+
assert response.status == 200
700+
assert await response.json() == {"data": {"test": "Hello WorldHello World"}}

0 commit comments

Comments
 (0)