mirror of
https://github.com/graphql-python/graphene-django.git
synced 2025-07-16 11:12:20 +03:00
Let django emit 500 responses on application server errors
This commit is contained in:
parent
d5e71bc9be
commit
60164d8e7a
|
@ -12,7 +12,7 @@ from django.views.decorators.csrf import ensure_csrf_cookie
|
||||||
|
|
||||||
from graphql import get_default_backend
|
from graphql import get_default_backend
|
||||||
from graphql.error import format_error as format_graphql_error
|
from graphql.error import format_error as format_graphql_error
|
||||||
from graphql.error import GraphQLError
|
from graphql.error import GraphQLError, GraphQLSyntaxError
|
||||||
from graphql.execution import ExecutionResult
|
from graphql.execution import ExecutionResult
|
||||||
from graphql.type.schema import GraphQLSchema
|
from graphql.type.schema import GraphQLSchema
|
||||||
|
|
||||||
|
@ -245,10 +245,10 @@ class GraphQLView(View):
|
||||||
return None
|
return None
|
||||||
raise HttpError(HttpResponseBadRequest("Must provide query string."))
|
raise HttpError(HttpResponseBadRequest("Must provide query string."))
|
||||||
|
|
||||||
|
backend = self.get_backend(request)
|
||||||
try:
|
try:
|
||||||
backend = self.get_backend(request)
|
|
||||||
document = backend.document_from_string(self.schema, query)
|
document = backend.document_from_string(self.schema, query)
|
||||||
except Exception as e:
|
except GraphQLSyntaxError as e:
|
||||||
return ExecutionResult(errors=[e], invalid=True)
|
return ExecutionResult(errors=[e], invalid=True)
|
||||||
|
|
||||||
if request.method.lower() == "get":
|
if request.method.lower() == "get":
|
||||||
|
@ -266,13 +266,13 @@ class GraphQLView(View):
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
try:
|
extra_options = {}
|
||||||
extra_options = {}
|
if self.executor:
|
||||||
if self.executor:
|
# We only include it optionally since
|
||||||
# We only include it optionally since
|
# executor is not a valid argument in all backends
|
||||||
# executor is not a valid argument in all backends
|
extra_options["executor"] = self.executor
|
||||||
extra_options["executor"] = self.executor
|
|
||||||
|
|
||||||
|
try:
|
||||||
return document.execute(
|
return document.execute(
|
||||||
root=self.get_root_value(request),
|
root=self.get_root_value(request),
|
||||||
variables=variables,
|
variables=variables,
|
||||||
|
@ -281,7 +281,7 @@ class GraphQLView(View):
|
||||||
middleware=self.get_middleware(request),
|
middleware=self.get_middleware(request),
|
||||||
**extra_options
|
**extra_options
|
||||||
)
|
)
|
||||||
except Exception as e:
|
except GraphQLError as e:
|
||||||
return ExecutionResult(errors=[e], invalid=True)
|
return ExecutionResult(errors=[e], invalid=True)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
|
|
Loading…
Reference in New Issue
Block a user