Skip to content

Commit 1972b27

Browse files
feat: add support for execution_context_class (#100)
Adds support for a custom execution context class as supported by graphql-core Co-authored-by: Alvin Chow <[email protected]>
1 parent 184ba72 commit 1972b27

File tree

16 files changed

+130
-15
lines changed

16 files changed

+130
-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
@@ -35,6 +35,7 @@ class GraphQLView:
3535
graphiql_html_title = None
3636
middleware = None
3737
validation_rules = None
38+
execution_context_class = None
3839
batch = False
3940
jinja_env = None
4041
max_age = 86400
@@ -83,6 +84,9 @@ def get_validation_rules(self):
8384
return specified_rules
8485
return self.validation_rules
8586

87+
def get_execution_context_class(self):
88+
return self.execution_context_class
89+
8690
@staticmethod
8791
async def parse_body(request):
8892
content_type = request.content_type
@@ -158,6 +162,7 @@ async def __call__(self, request):
158162
context_value=self.get_context(request),
159163
middleware=self.get_middleware(),
160164
validation_rules=self.get_validation_rules(),
165+
execution_context_class=self.get_execution_context_class(),
161166
)
162167

163168
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
@@ -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
enable_async = False
4243
subscriptions = None
@@ -83,6 +84,9 @@ def get_validation_rules(self):
8384
return specified_rules
8485
return self.validation_rules
8586

87+
def get_execution_context_class(self):
88+
return self.execution_context_class
89+
8690
async def dispatch_request(self):
8791
try:
8892
request_method = request.method.lower()
@@ -106,6 +110,7 @@ async def dispatch_request(self):
106110
context_value=self.get_context(),
107111
middleware=self.get_middleware(),
108112
validation_rules=self.get_validation_rules(),
113+
execution_context_class=self.get_execution_context_class(),
109114
)
110115
exec_res = (
111116
[

graphql_server/sanic/graphqlview.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ class GraphQLView(HTTPMethodView):
3737
graphiql_html_title = None
3838
middleware = None
3939
validation_rules = None
40+
execution_context_class = None
4041
batch = False
4142
jinja_env = None
4243
max_age = 86400
@@ -85,6 +86,9 @@ def get_validation_rules(self):
8586
return specified_rules
8687
return self.validation_rules
8788

89+
def get_execution_context_class(self):
90+
return self.execution_context_class
91+
8892
async def __handle_request(self, request, *args, **kwargs):
8993
try:
9094
request_method = request.method.lower()
@@ -112,6 +116,7 @@ async def __handle_request(self, request, *args, **kwargs):
112116
context_value=self.get_context(request),
113117
middleware=self.get_middleware(),
114118
validation_rules=self.get_validation_rules(),
119+
execution_context_class=self.get_execution_context_class(),
115120
)
116121
exec_res = (
117122
[

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,

setup.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from re import search
2-
from setuptools import setup, find_packages
2+
3+
from setuptools import find_packages, setup
34

45
install_requires = [
56
"graphql-core>=3.2,<3.3",

0 commit comments

Comments
 (0)