Skip to content

Commit d15ab00

Browse files
committed
Add extensions support to GraphQLError
1 parent 9202021 commit d15ab00

File tree

3 files changed

+11
-2
lines changed

3 files changed

+11
-2
lines changed

graphql/error/base.py

Lines changed: 4 additions & 1 deletion
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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,7 @@ def format_error(error):
1818
if error.path is not None:
1919
formatted_error["path"] = error.path
2020

21+
if error.extensions is not None:
22+
formatted_error["extensions"] = error.extensions
23+
2124
return formatted_error

graphql/error/located_error.py

Lines changed: 4 additions & 1 deletion
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)