From d15ab00fadc853ed8182d6f5b0f7b5d2ef369683 Mon Sep 17 00:00:00 2001 From: odero Date: Tue, 6 Nov 2018 14:40:47 +0300 Subject: [PATCH] Add extensions support to GraphQLError --- graphql/error/base.py | 5 ++++- graphql/error/format_error.py | 3 +++ graphql/error/located_error.py | 5 ++++- 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/graphql/error/base.py b/graphql/error/base.py index c57d0959..0aae96b0 100644 --- a/graphql/error/base.py +++ b/graphql/error/base.py @@ -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): @@ -19,6 +19,7 @@ class GraphQLError(Exception): "_positions", "_locations", "path", + "extensions", ) def __init__( @@ -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) @@ -40,6 +42,7 @@ def __init__( self._positions = positions self._locations = locations self.path = path + self.extensions = extensions return None @property diff --git a/graphql/error/format_error.py b/graphql/error/format_error.py index fd162c82..6ef850b3 100644 --- a/graphql/error/format_error.py +++ b/graphql/error/format_error.py @@ -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 diff --git a/graphql/error/located_error.py b/graphql/error/located_error.py index fe84e495..1cd2553e 100644 --- a/graphql/error/located_error.py +++ b/graphql/error/located_error.py @@ -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