mirror of
https://github.com/graphql-python/graphene.git
synced 2024-11-11 04:07:16 +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
|
||||
|
||||
def execute_query(self, request, query):
|
||||
result = self.schema.execute(query, root=object())
|
||||
data = self.format_result(result)
|
||||
if not query:
|
||||
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)
|
||||
|
||||
def get(self, request, *args, **kwargs):
|
||||
|
|
Loading…
Reference in New Issue
Block a user