mirror of
https://github.com/graphql-python/graphene.git
synced 2024-11-13 13:16:49 +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):
|
||||||
result = self.schema.execute(query, root=object())
|
if not query:
|
||||||
data = self.format_result(result)
|
data = {
|
||||||
|
"errors": [{
|
||||||
|
"message": "Must provide query string."
|
||||||
|
}]
|
||||||
|
}
|
||||||
|
else:
|
||||||
|
try:
|
||||||
|
result = self.schema.execute(query, root=object())
|
||||||
|
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