File tree 3 files changed +30
-6
lines changed
3 files changed +30
-6
lines changed Original file line number Diff line number Diff line change 1
- # ` graphql-django-view ` [ ![ Build Status] ( https://travis-ci.org/graphql-python/graphql-django-view.svg?branch=master )] ( https://travis-ci.org/graphql-python/graphql-django-view ) [ ![ Coverage Status] ( https://coveralls.io/repos/graphql-python/graphql-django-view/badge.svg?branch=master&service=github )] ( https://coveralls.io/github/graphql-python/graphql-django-view?branch=master ) [ ![ PyPI version] ( https://badge.fury.io/py/graphql-django-view.svg )] ( https://badge.fury.io/py/graphql-django-view )
1
+ # ` graphql-django-view `
2
+
3
+ [ ![ Build Status] ( https://travis-ci.org/graphql-python/graphql-django-view.svg?branch=master )] ( https://travis-ci.org/graphql-python/graphql-django-view ) [ ![ Coverage Status] ( https://coveralls.io/repos/graphql-python/graphql-django-view/badge.svg?branch=master&service=github )] ( https://coveralls.io/github/graphql-python/graphql-django-view?branch=master ) [ ![ PyPI version] ( https://badge.fury.io/py/graphql-django-view.svg )] ( https://badge.fury.io/py/graphql-django-view )
2
4
3
5
A ` django ` view that will execute a ` GraphQLSchema ` using a given ` Executor ` .
4
6
5
- This is a WIP and does not currently work.
7
+ ## Usage
8
+ Use it like you would any other Django View.
9
+
10
+ ``` python
11
+ urlpatterns = [
12
+ url(r ' ^ graphql' , GraphQLView.as_view(schema = Schema)),
13
+ ]
14
+ ```
15
+
16
+ ### Supported options
17
+ * ` schema ` : The ` GraphQLSchema ` object that you want the view to execute when it gets a valid request.
18
+ * ` pretty ` : Whether or not you want the response to be pretty printed JSON.
19
+ * ` executor ` : The ` Executor ` that you want to use to execute queries.
20
+ * ` root_value ` : The ` root_value ` you want to provide to ` executor.execute ` .
21
+
22
+ You can also subclass ` GraphQLView ` and overwrite ` get_root_value(self, request) ` to have a dynamic root value
23
+ per request.
24
+
25
+ ``` python
26
+ class UserRootValue (GraphQLView ):
27
+ def get_root_value (self , request ):
28
+ return request.user
6
29
7
- Do not use this yet.
30
+ ```
Original file line number Diff line number Diff line change @@ -31,7 +31,8 @@ def __init__(self, **kwargs):
31
31
32
32
assert isinstance (self .schema , GraphQLSchema ), 'A Schema is required to be provided to GraphQLView.'
33
33
34
- def get_root_value (self ):
34
+ # noinspection PyUnusedLocal
35
+ def get_root_value (self , request ):
35
36
return self .root_value
36
37
37
38
def dispatch (self , request , * args , ** kwargs ):
@@ -120,7 +121,7 @@ def execute_graphql_request(self, request):
120
121
return self .executor .execute (
121
122
self .schema ,
122
123
document_ast ,
123
- self .get_root_value (),
124
+ self .get_root_value (request ),
124
125
variables ,
125
126
operation_name ,
126
127
validate_ast = False
Original file line number Diff line number Diff line change 4
4
5
5
setup (
6
6
name = 'graphql-django-view' ,
7
- version = '0.0-dev ' ,
7
+ version = '1. 0.0' ,
8
8
description = 'A django view that will execute a GraphQL Schema' ,
9
9
url = 'https://github.com/graphql-python/graphql-django-view' ,
10
10
download_url = 'https://github.com/graphql-python/graphql-django-view/releases' ,
You can’t perform that action at this time.
0 commit comments