Skip to content

Commit db546b8

Browse files
committed
Updated grapqhl-core version to 0.5.0
1 parent 26efa50 commit db546b8

File tree

7 files changed

+33
-32
lines changed

7 files changed

+33
-32
lines changed

graphql_django_view/__init__.py

+16-14
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22
from django.http import HttpResponse, HttpResponseNotAllowed
33
from django.http.response import HttpResponseBadRequest
44
from django.views.generic import View
5-
from graphql.core import Source, parse
6-
from graphql.core.error import GraphQLError, format_error as format_graphql_error
7-
from graphql.core.execution import ExecutionResult, get_default_executor
8-
from graphql.core.type.schema import GraphQLSchema
9-
from graphql.core.utils.get_operation_ast import get_operation_ast
5+
from graphql import Source, parse, execute, validate
6+
from graphql.error import GraphQLError, format_error as format_graphql_error
7+
from graphql.execution import ExecutionResult
8+
from graphql.type.schema import GraphQLSchema
9+
from graphql.utils.get_operation_ast import get_operation_ast
1010
import six
1111

1212

@@ -25,17 +25,13 @@ class GraphQLView(View):
2525

2626
def __init__(self, **kwargs):
2727
super(GraphQLView, self).__init__(**kwargs)
28-
29-
if not self.executor:
30-
self.executor = get_default_executor()
31-
3228
assert isinstance(self.schema, GraphQLSchema), 'A Schema is required to be provided to GraphQLView.'
3329

3430
# noinspection PyUnusedLocal
3531
def get_root_value(self, request):
3632
return self.root_value
3733

38-
def get_request_context(self, request):
34+
def get_context(self, request):
3935
return request
4036

4137
def dispatch(self, request, *args, **kwargs):
@@ -97,7 +93,7 @@ def parse_body(self, request):
9793
return {}
9894

9995
def execute(self, *args, **kwargs):
100-
return self.executor.execute(self.schema, *args, **kwargs)
96+
return execute(self.schema, *args, **kwargs)
10197

10298
def execute_graphql_request(self, request):
10399
query, variables, operation_name = self.get_graphql_params(request, self.parse_body(request))
@@ -109,6 +105,12 @@ def execute_graphql_request(self, request):
109105

110106
try:
111107
document_ast = parse(source)
108+
validation_errors = validate(self.schema, document_ast)
109+
if validation_errors:
110+
return ExecutionResult(
111+
errors=validation_errors,
112+
invalid=True,
113+
)
112114
except Exception as e:
113115
return ExecutionResult(errors=[e], invalid=True)
114116

@@ -122,10 +124,10 @@ def execute_graphql_request(self, request):
122124
try:
123125
return self.execute(
124126
document_ast,
125-
self.get_root_value(request),
126-
variables,
127+
root_value=self.get_root_value(request),
128+
variable_values=variables,
127129
operation_name=operation_name,
128-
request_context=self.get_request_context(request)
130+
context_value=self.get_context(request)
129131
)
130132
except Exception as e:
131133
return ExecutionResult(errors=[e], invalid=True)

pytest.ini

-3
This file was deleted.

setup.cfg

+4
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
11
[flake8]
22
exclude = tests,scripts,setup.py,docs
33
max-line-length = 160
4+
5+
[pytest]
6+
DJANGO_SETTINGS_MODULE=tests.settings
7+
norecursedirs = venv .tox .cache

setup.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
from setuptools import setup, find_packages
22

3-
required_packages = ['graphql-core>=0.4.15', 'django>=1.8.0']
3+
required_packages = ['graphql-core>=0.5.0', 'django>=1.8.0']
44

55
setup(
66
name='graphql-django-view',
7-
version='1.1.1',
7+
version='1.2.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',

tests/schema.py

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
from graphql.core.type.definition import GraphQLArgument, GraphQLField, GraphQLNonNull, GraphQLObjectType
2-
from graphql.core.type.scalars import GraphQLString
3-
from graphql.core.type.schema import GraphQLSchema
1+
from graphql.type.definition import GraphQLArgument, GraphQLField, GraphQLNonNull, GraphQLObjectType
2+
from graphql.type.scalars import GraphQLString
3+
from graphql.type.schema import GraphQLSchema
44

55

6-
def resolve_raises(o, a, i):
6+
def resolve_raises(*_):
77
raise Exception("Throws!")
88

99

@@ -12,13 +12,13 @@ def resolve_raises(o, a, i):
1212
fields={
1313
'thrower': GraphQLField(GraphQLNonNull(GraphQLString), resolver=resolve_raises),
1414
'request': GraphQLField(GraphQLNonNull(GraphQLString),
15-
resolver=lambda obj, args, info: info.request_context.GET.get('q')),
15+
resolver=lambda obj, args, request, info: request.GET.get('q')),
1616
'test': GraphQLField(
1717
type=GraphQLString,
1818
args={
1919
'who': GraphQLArgument(GraphQLString)
2020
},
21-
resolver=lambda obj, args, info: 'Hello %s' % (args.get('who') or 'World')
21+
resolver=lambda obj, args, request, info: 'Hello %s' % (args.get('who') or 'World')
2222
)
2323
}
2424
)

tests/test_http.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -405,7 +405,7 @@ def test_handles_unsupported_http_methods(client):
405405
}
406406

407407

408-
def test_passes_request_into_request_context(client):
408+
def test_passes_request_into_context_request(client):
409409
response = client.get(url_string(query='{request}', q='testing'))
410410

411411
assert response.status_code == 200

tox.ini

+4-6
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ setenv =
88
deps =
99
pytest>=2.7.2
1010
pytest-django>=2.9.1
11-
graphql-core>=0.4.7b2
11+
https://github.com/graphql-python/graphql-core/archive/master.zip
1212
django>=1.8.0
1313
pytest-cov
1414
commands =
@@ -18,15 +18,13 @@ commands =
1818
basepython=python3.5
1919
deps = flake8
2020
commands =
21-
pip install -e .
2221
flake8 graphql_django_view
2322

2423
[testenv:import-order]
2524
basepython=python3.5
2625
deps =
27-
import-order
28-
graphql-core>=0.4.7b2
26+
isort
27+
https://github.com/graphql-python/graphql-core/archive/master.zip
2928
django>=1.8.0
3029
commands =
31-
pip install -e .
32-
import-order graphql_django_view
30+
isort --check-only graphql_django_view/ -rc

0 commit comments

Comments
 (0)