Skip to content

Commit 70dffa9

Browse files
authored
Merge pull request #212 from maqquettex/fix_cbv_inheritance
Inheritance support for GraphQLView (class attributes)
2 parents d2c1e7c + 3682fe0 commit 70dffa9

File tree

3 files changed

+36
-4
lines changed

3 files changed

+36
-4
lines changed

graphene_django/tests/test_views.py

+18
Original file line numberDiff line numberDiff line change
@@ -400,6 +400,24 @@ def test_allows_post_with_get_operation_name(client):
400400
}
401401

402402

403+
@pytest.mark.urls('graphene_django.tests.urls_inherited')
404+
def test_inherited_class_with_attributes_works(client):
405+
inherited_url = '/graphql/inherited/'
406+
# Check schema and pretty attributes work
407+
response = client.post(url_string(inherited_url, query='{test}'))
408+
assert response.content.decode() == (
409+
'{\n'
410+
' "data": {\n'
411+
' "test": "Hello World"\n'
412+
' }\n'
413+
'}'
414+
)
415+
416+
# Check graphiql works
417+
response = client.get(url_string(inherited_url), HTTP_ACCEPT='text/html')
418+
assert response.status_code == 200
419+
420+
403421
@pytest.mark.urls('graphene_django.tests.urls_pretty')
404422
def test_supports_pretty_printing(client):
405423
response = client.get(url_string(query='{test}'))
+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
from django.conf.urls import url
2+
3+
from ..views import GraphQLView
4+
from .schema_view import schema
5+
6+
class CustomGraphQLView(GraphQLView):
7+
schema = schema
8+
graphiql = True
9+
pretty = True
10+
11+
12+
urlpatterns = [
13+
url(r'^graphql/inherited/$', CustomGraphQLView.as_view()),
14+
]

graphene_django/views.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -72,14 +72,14 @@ def __init__(self, schema=None, executor=None, middleware=None, root_value=None,
7272
if middleware is None:
7373
middleware = graphene_settings.MIDDLEWARE
7474

75-
self.schema = schema
75+
self.schema = self.schema or schema
7676
if middleware is not None:
7777
self.middleware = list(instantiate_middleware(middleware))
7878
self.executor = executor
7979
self.root_value = root_value
80-
self.pretty = pretty
81-
self.graphiql = graphiql
82-
self.batch = batch
80+
self.pretty = self.pretty or pretty
81+
self.graphiql = self.graphiql or graphiql
82+
self.batch = self.batch or batch
8383

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

0 commit comments

Comments
 (0)