Skip to content

Commit ff6b490

Browse files
committed
Added to_dict method to ExecutionResult
1 parent 24be647 commit ff6b490

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

graphql/execution/base.py

+14
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
default_resolve_fn,
1111
get_field_def
1212
)
13+
from ..error.format_error import format_error as default_format_error
1314

1415

1516
class ExecutionResult(object):
@@ -38,6 +39,19 @@ def __eq__(self, other):
3839
self.invalid == other.invalid
3940
)
4041
)
42+
43+
def to_dict(self, format_error=None, dict_class=dict):
44+
if format_error is None:
45+
format_error = default_format_error
46+
47+
response = dict_class()
48+
if self.errors:
49+
response['errors'] = [format_error(e) for e in self.errors]
50+
51+
if not self.invalid:
52+
response['data'] = self.data
53+
54+
return response
4155

4256

4357
class ResolveInfo(object):

0 commit comments

Comments
 (0)