mirror of
https://github.com/graphql-python/graphene.git
synced 2024-11-26 19:43:56 +03:00
Improved Django GraphQL view error handling
This commit is contained in:
parent
dcd8edb59a
commit
b0e3b3a3af
|
@ -23,8 +23,21 @@ class GraphQLView(View):
|
||||||
return data
|
return data
|
||||||
|
|
||||||
def execute_query(self, request, query):
|
def execute_query(self, request, query):
|
||||||
|
if not query:
|
||||||
|
data = {
|
||||||
|
"errors": [{
|
||||||
|
"message": "Must provide query string."
|
||||||
|
}]
|
||||||
|
}
|
||||||
|
else:
|
||||||
|
try:
|
||||||
result = self.schema.execute(query, root=object())
|
result = self.schema.execute(query, root=object())
|
||||||
data = self.format_result(result)
|
data = self.format_result(result)
|
||||||
|
except Exception, e:
|
||||||
|
data = {
|
||||||
|
"errors": [{"message": str(e)}]
|
||||||
|
}
|
||||||
|
|
||||||
return JsonResponse(data)
|
return JsonResponse(data)
|
||||||
|
|
||||||
def get(self, request, *args, **kwargs):
|
def get(self, request, *args, **kwargs):
|
||||||
|
|
Loading…
Reference in New Issue
Block a user