Skip to content

Commit 1bef922

Browse files
committed
Update readme.md.
1 parent bab2bbd commit 1bef922

File tree

3 files changed

+30
-6
lines changed

3 files changed

+30
-6
lines changed

README.md

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,30 @@
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)
24

35
A `django` view that will execute a `GraphQLSchema` using a given `Executor`.
46

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
629

7-
Do not use this yet.
30+
```

graphql_django_view/__init__.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@ def __init__(self, **kwargs):
3131

3232
assert isinstance(self.schema, GraphQLSchema), 'A Schema is required to be provided to GraphQLView.'
3333

34-
def get_root_value(self):
34+
# noinspection PyUnusedLocal
35+
def get_root_value(self, request):
3536
return self.root_value
3637

3738
def dispatch(self, request, *args, **kwargs):
@@ -120,7 +121,7 @@ def execute_graphql_request(self, request):
120121
return self.executor.execute(
121122
self.schema,
122123
document_ast,
123-
self.get_root_value(),
124+
self.get_root_value(request),
124125
variables,
125126
operation_name,
126127
validate_ast=False

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
setup(
66
name='graphql-django-view',
7-
version='0.0-dev',
7+
version='1.0.0',
88
description='A django view that will execute a GraphQL Schema',
99
url='https://github.com/graphql-python/graphql-django-view',
1010
download_url='https://github.com/graphql-python/graphql-django-view/releases',

0 commit comments

Comments
 (0)