Skip to content

Updated ExecutionResult.formatted #130

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 28, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions src/graphql/execution/execute.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,9 +131,12 @@ def __iter__(self) -> Iterable[Any]:
@property
def formatted(self) -> Dict[str, Any]:
"""Get execution result formatted according to the specification."""
formatted_errors = ([err.formatted for err in self.errors]
if self.errors is not None
else None)
if self.extensions is None:
return dict(data=self.data, errors=self.errors)
return dict(data=self.data, errors=self.errors, extensions=self.extensions)
return dict(data=self.data, errors=formatted_errors)
return dict(data=self.data, errors=formatted_errors, extensions=self.extensions)

def __eq__(self, other: Any) -> bool:
if isinstance(other, dict):
Expand Down
4 changes: 2 additions & 2 deletions tests/execution/test_execution_result.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,11 @@ def prints_a_representation():

def formats_properly():
res = ExecutionResult(data, errors)
assert res.formatted == {"data": data, "errors": errors}
assert res.formatted == {"data": data, "errors": [{'message': 'Some error', 'locations': None, 'path': None}]}
res = ExecutionResult(data, errors, extensions)
assert res.formatted == {
"data": data,
"errors": errors,
"errors": [{'message': 'Some error', 'locations': None, 'path': None}],
"extensions": extensions,
}

Expand Down