Skip to content

Commit 934deca

Browse files
committed
Improved ExecutionResult typing
1 parent 0cef6fb commit 934deca

File tree

2 files changed

+7
-6
lines changed

2 files changed

+7
-6
lines changed

graphql/error/format_error.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,11 @@
44

55
# Necessary for static type checking
66
if False: # flake8: noqa
7-
from .base import GraphQLError
8-
from .located_error import GraphQLLocatedError
97
from typing import Any, Dict, Union
108

119

1210
def format_error(error):
13-
# type: (Union[GraphQLError, GraphQLLocatedError]) -> Dict[str, Any]
11+
# type: (Exception) -> Dict[str, Any]
1412
formatted_error = {"message": text_type(error)} # type: Dict[str, Any]
1513
if isinstance(error, GraphQLError):
1614
if error.locations is not None:

graphql/execution/base.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,12 @@
1010
default_resolve_fn,
1111
get_field_def,
1212
)
13+
from ..pyutils.ordereddict import OrderedDict
1314
from ..error.format_error import format_error as default_format_error
1415

1516
# Necessary for static type checking
1617
if False: # flake8: noqa
17-
from typing import Any, Optional, Dict, List, Union
18+
from typing import Any, Optional, Dict, List, Union, Callable, Type
1819
from ..language.ast import Field, OperationDefinition
1920
from ..type.definition import GraphQLList, GraphQLObjectType, GraphQLScalarType
2021
from ..type.schema import GraphQLSchema
@@ -28,7 +29,7 @@ class ExecutionResult(object):
2829
__slots__ = "data", "errors", "invalid", "extensions"
2930

3031
def __init__(self, data=None, errors=None, invalid=False, extensions=None):
31-
# type: (Any, Any, bool, Optional[Any]) -> None
32+
# type: (Optional[Dict], Optional[List[Exception]], bool, Optional[Any]) -> None
3233
self.data = data
3334
self.errors = errors
3435
self.extensions = extensions or dict()
@@ -39,14 +40,16 @@ def __init__(self, data=None, errors=None, invalid=False, extensions=None):
3940
self.invalid = invalid
4041

4142
def __eq__(self, other):
43+
# type: (Any) -> bool
4244
return self is other or (
4345
isinstance(other, ExecutionResult)
4446
and self.data == other.data
4547
and self.errors == other.errors
4648
and self.invalid == other.invalid
4749
)
4850

49-
def to_dict(self, format_error=None, dict_class=dict):
51+
def to_dict(self, format_error=None, dict_class=OrderedDict):
52+
# type: (Optional[Callable[[Exception], Dict]], Type[Dict]) -> Dict[str, Any]
5053
if format_error is None:
5154
format_error = default_format_error
5255

0 commit comments

Comments
 (0)