Skip to content

Commit 8d71342

Browse files
mlorenzanaMike Lorenzana
andauthored
Return formatted errors in formatted execution result (fixes #129)
Co-authored-by: Mike Lorenzana <michael.lorenzana@coxautoinc.com>
1 parent 8ad948a commit 8d71342

File tree

2 files changed

+7
-4
lines changed

2 files changed

+7
-4
lines changed

src/graphql/execution/execute.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -131,9 +131,12 @@ def __iter__(self) -> Iterable[Any]:
131131
@property
132132
def formatted(self) -> Dict[str, Any]:
133133
"""Get execution result formatted according to the specification."""
134+
formatted_errors = ([err.formatted for err in self.errors]
135+
if self.errors is not None
136+
else None)
134137
if self.extensions is None:
135-
return dict(data=self.data, errors=self.errors)
136-
return dict(data=self.data, errors=self.errors, extensions=self.extensions)
138+
return dict(data=self.data, errors=formatted_errors)
139+
return dict(data=self.data, errors=formatted_errors, extensions=self.extensions)
137140

138141
def __eq__(self, other: Any) -> bool:
139142
if isinstance(other, dict):

tests/execution/test_execution_result.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,11 @@ def prints_a_representation():
3434

3535
def formats_properly():
3636
res = ExecutionResult(data, errors)
37-
assert res.formatted == {"data": data, "errors": errors}
37+
assert res.formatted == {"data": data, "errors": [{'message': 'Some error', 'locations': None, 'path': None}]}
3838
res = ExecutionResult(data, errors, extensions)
3939
assert res.formatted == {
4040
"data": data,
41-
"errors": errors,
41+
"errors": [{'message': 'Some error', 'locations': None, 'path': None}],
4242
"extensions": extensions,
4343
}
4444

0 commit comments

Comments
 (0)