Skip to content

Commit 3ba7f92

Browse files
oderoekampf
authored andcommitted
Add extensions support to GraphQLError (#214)
1 parent d8e9d3a commit 3ba7f92

File tree

3 files changed

+11
-2
lines changed

3 files changed

+11
-2
lines changed

graphql/error/base.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
from ..language.source import Source
77
from ..language.location import SourceLocation
88
from types import TracebackType
9-
from typing import Optional, List, Any, Union
9+
from typing import Dict, Optional, List, Any, Union
1010

1111

1212
class GraphQLError(Exception):
@@ -19,6 +19,7 @@ class GraphQLError(Exception):
1919
"_positions",
2020
"_locations",
2121
"path",
22+
"extensions",
2223
)
2324

2425
def __init__(
@@ -30,6 +31,7 @@ def __init__(
3031
positions=None, # type: Optional[Any]
3132
locations=None, # type: Optional[Any]
3233
path=None, # type: Union[List[Union[int, str]], List[str], None]
34+
extensions=None, # type: Optional[Dict[str, Any]]
3335
):
3436
# type: (...) -> None
3537
super(GraphQLError, self).__init__(message)
@@ -40,6 +42,7 @@ def __init__(
4042
self._positions = positions
4143
self._locations = locations
4244
self.path = path
45+
self.extensions = extensions
4346
return None
4447

4548
@property

graphql/error/format_error.py

+3
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,7 @@ def format_error(error):
2121
if error.path is not None:
2222
formatted_error["path"] = error.path
2323

24+
if error.extensions is not None:
25+
formatted_error["extensions"] = error.extensions
26+
2427
return formatted_error

graphql/error/located_error.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,10 @@ def __init__(
3030
if not stack:
3131
stack = sys.exc_info()[2]
3232

33+
extensions = (
34+
getattr(original_error, "extensions", None) if original_error else None
35+
)
3336
super(GraphQLLocatedError, self).__init__(
34-
message=message, nodes=nodes, stack=stack, path=path
37+
message=message, nodes=nodes, stack=stack, path=path, extensions=extensions
3538
)
3639
self.original_error = original_error

0 commit comments

Comments
 (0)