mirror of
https://github.com/graphql-python/graphene-django.git
synced 2025-01-31 11:48:38 +03:00
Merge pull request #212 from maqquettex/fix_cbv_inheritance
Inheritance support for GraphQLView (class attributes)
This commit is contained in:
commit
70dffa94e7
|
@ -400,6 +400,24 @@ def test_allows_post_with_get_operation_name(client):
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.urls('graphene_django.tests.urls_inherited')
|
||||||
|
def test_inherited_class_with_attributes_works(client):
|
||||||
|
inherited_url = '/graphql/inherited/'
|
||||||
|
# Check schema and pretty attributes work
|
||||||
|
response = client.post(url_string(inherited_url, query='{test}'))
|
||||||
|
assert response.content.decode() == (
|
||||||
|
'{\n'
|
||||||
|
' "data": {\n'
|
||||||
|
' "test": "Hello World"\n'
|
||||||
|
' }\n'
|
||||||
|
'}'
|
||||||
|
)
|
||||||
|
|
||||||
|
# Check graphiql works
|
||||||
|
response = client.get(url_string(inherited_url), HTTP_ACCEPT='text/html')
|
||||||
|
assert response.status_code == 200
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.urls('graphene_django.tests.urls_pretty')
|
@pytest.mark.urls('graphene_django.tests.urls_pretty')
|
||||||
def test_supports_pretty_printing(client):
|
def test_supports_pretty_printing(client):
|
||||||
response = client.get(url_string(query='{test}'))
|
response = client.get(url_string(query='{test}'))
|
||||||
|
|
14
graphene_django/tests/urls_inherited.py
Normal file
14
graphene_django/tests/urls_inherited.py
Normal file
|
@ -0,0 +1,14 @@
|
||||||
|
from django.conf.urls import url
|
||||||
|
|
||||||
|
from ..views import GraphQLView
|
||||||
|
from .schema_view import schema
|
||||||
|
|
||||||
|
class CustomGraphQLView(GraphQLView):
|
||||||
|
schema = schema
|
||||||
|
graphiql = True
|
||||||
|
pretty = True
|
||||||
|
|
||||||
|
|
||||||
|
urlpatterns = [
|
||||||
|
url(r'^graphql/inherited/$', CustomGraphQLView.as_view()),
|
||||||
|
]
|
|
@ -72,14 +72,14 @@ class GraphQLView(View):
|
||||||
if middleware is None:
|
if middleware is None:
|
||||||
middleware = graphene_settings.MIDDLEWARE
|
middleware = graphene_settings.MIDDLEWARE
|
||||||
|
|
||||||
self.schema = schema
|
self.schema = self.schema or schema
|
||||||
if middleware is not None:
|
if middleware is not None:
|
||||||
self.middleware = list(instantiate_middleware(middleware))
|
self.middleware = list(instantiate_middleware(middleware))
|
||||||
self.executor = executor
|
self.executor = executor
|
||||||
self.root_value = root_value
|
self.root_value = root_value
|
||||||
self.pretty = pretty
|
self.pretty = self.pretty or pretty
|
||||||
self.graphiql = graphiql
|
self.graphiql = self.graphiql or graphiql
|
||||||
self.batch = batch
|
self.batch = self.batch or batch
|
||||||
|
|
||||||
assert isinstance(
|
assert isinstance(
|
||||||
self.schema, GraphQLSchema), 'A Schema is required to be provided to GraphQLView.'
|
self.schema, GraphQLSchema), 'A Schema is required to be provided to GraphQLView.'
|
||||||
|
|
Loading…
Reference in New Issue
Block a user