Skip to content

Add extensions support to GraphQLError #214

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 1 commit into from
May 4, 2019
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
5 changes: 4 additions & 1 deletion graphql/error/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from ..language.source import Source
from ..language.location import SourceLocation
from types import TracebackType
from typing import Optional, List, Any, Union
from typing import Dict, Optional, List, Any, Union


class GraphQLError(Exception):
Expand All @@ -19,6 +19,7 @@ class GraphQLError(Exception):
"_positions",
"_locations",
"path",
"extensions",
)

def __init__(
Expand All @@ -30,6 +31,7 @@ def __init__(
positions=None, # type: Optional[Any]
locations=None, # type: Optional[Any]
path=None, # type: Union[List[Union[int, str]], List[str], None]
extensions=None, # type: Optional[Dict[str, Any]]
):
# type: (...) -> None
super(GraphQLError, self).__init__(message)
Expand All @@ -40,6 +42,7 @@ def __init__(
self._positions = positions
self._locations = locations
self.path = path
self.extensions = extensions
return None
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This return None seems unnecessary.
Any idea why it's here?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My guess would be for the typings check. It was there prior to this PR though

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍


@property
Expand Down
3 changes: 3 additions & 0 deletions graphql/error/format_error.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,7 @@ def format_error(error):
if error.path is not None:
formatted_error["path"] = error.path

if error.extensions is not None:
formatted_error["extensions"] = error.extensions

return formatted_error
5 changes: 4 additions & 1 deletion graphql/error/located_error.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,10 @@ def __init__(
if not stack:
stack = sys.exc_info()[2]

extensions = (
getattr(original_error, "extensions", None) if original_error else None
)
super(GraphQLLocatedError, self).__init__(
message=message, nodes=nodes, stack=stack, path=path
message=message, nodes=nodes, stack=stack, path=path, extensions=extensions
)
self.original_error = original_error