Skip to content

Commit 095b475

Browse files
committed
Rename MaybeAwaitable to AwaitableOrValue
Replicates graphql/graphql-js@329f357
1 parent 223d740 commit 095b475

File tree

10 files changed

+63
-56
lines changed

10 files changed

+63
-56
lines changed

Pipfile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,6 @@ pyyaml = ">=4.0"
2020

2121
[pipenv]
2222
allow_prereleases = true
23+
24+
[packages]
25+
graphql-core-next = {editable = true,path = "."}

Pipfile.lock

Lines changed: 28 additions & 24 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/modules/pyutils.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ PyUtils
1313
.. autofunction:: is_integer
1414
.. autofunction:: is_invalid
1515
.. autofunction:: is_nullish
16-
.. autoclass:: MaybeAwaitable
16+
.. autoclass:: AwaitableOrValue
1717
.. autofunction:: or_list
1818
.. autofunction:: quoted_or_list
1919
.. autofunction:: suggestion_list

graphql/execution/execute.py

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
OperationType,
2727
SelectionSetNode,
2828
)
29-
from ..pyutils import inspect, is_invalid, is_nullish, MaybeAwaitable
29+
from ..pyutils import inspect, is_invalid, is_nullish, AwaitableOrValue
3030
from ..utilities import get_operation_root_type, type_from_ast
3131
from ..type import (
3232
GraphQLAbstractType,
@@ -116,7 +116,7 @@ def execute(
116116
type_resolver: GraphQLTypeResolver = None,
117117
middleware: Middleware = None,
118118
execution_context_class: Type["ExecutionContext"] = None,
119-
) -> MaybeAwaitable[ExecutionResult]:
119+
) -> AwaitableOrValue[ExecutionResult]:
120120
"""Execute a GraphQL operation.
121121
122122
Implements the "Evaluating requests" section of the GraphQL specification.
@@ -304,8 +304,8 @@ def build(
304304
)
305305

306306
def build_response(
307-
self, data: MaybeAwaitable[Optional[Dict[str, Any]]]
308-
) -> MaybeAwaitable[ExecutionResult]:
307+
self, data: AwaitableOrValue[Optional[Dict[str, Any]]]
308+
) -> AwaitableOrValue[ExecutionResult]:
309309
"""Build response.
310310
311311
Given a completed execution context and data, build the (data, errors) response
@@ -328,7 +328,7 @@ async def build_response_async():
328328

329329
def execute_operation(
330330
self, operation: OperationDefinitionNode, root_value: Any
331-
) -> Optional[MaybeAwaitable[Any]]:
331+
) -> Optional[AwaitableOrValue[Any]]:
332332
"""Execute an operation.
333333
334334
Implements the "Evaluating operations" section of the spec.
@@ -377,7 +377,7 @@ def execute_fields_serially(
377377
source_value: Any,
378378
path: Optional[ResponsePath],
379379
fields: Dict[str, List[FieldNode]],
380-
) -> MaybeAwaitable[Dict[str, Any]]:
380+
) -> AwaitableOrValue[Dict[str, Any]]:
381381
"""Execute the given fields serially.
382382
383383
Implements the "Evaluating selection sets" section of the spec for "write" mode.
@@ -427,7 +427,7 @@ def execute_fields(
427427
source_value: Any,
428428
path: Optional[ResponsePath],
429429
fields: Dict[str, List[FieldNode]],
430-
) -> MaybeAwaitable[Dict[str, Any]]:
430+
) -> AwaitableOrValue[Dict[str, Any]]:
431431
"""Execute the given fields concurrently.
432432
433433
Implements the "Evaluating selection sets" section of the spec for "read" mode.
@@ -581,7 +581,7 @@ def resolve_field(
581581
source: Any,
582582
field_nodes: List[FieldNode],
583583
path: ResponsePath,
584-
) -> MaybeAwaitable[Any]:
584+
) -> AwaitableOrValue[Any]:
585585
"""Resolve the field on the given source object.
586586
587587
In particular, this figures out the value that the field returns by calling its
@@ -652,7 +652,7 @@ def complete_value_catching_error(
652652
info: GraphQLResolveInfo,
653653
path: ResponsePath,
654654
result: Any,
655-
) -> MaybeAwaitable[Any]:
655+
) -> AwaitableOrValue[Any]:
656656
"""Complete a value while catching an error.
657657
658658
This is a small wrapper around completeValue which detects and logs errors in
@@ -713,7 +713,7 @@ def complete_value(
713713
info: GraphQLResolveInfo,
714714
path: ResponsePath,
715715
result: Any,
716-
) -> MaybeAwaitable[Any]:
716+
) -> AwaitableOrValue[Any]:
717717
"""Complete a value.
718718
719719
Implements the instructions for completeValue as defined in the "Field entries"
@@ -797,7 +797,7 @@ def complete_list_value(
797797
info: GraphQLResolveInfo,
798798
path: ResponsePath,
799799
result: Iterable[Any],
800-
) -> MaybeAwaitable[Any]:
800+
) -> AwaitableOrValue[Any]:
801801
"""Complete a list value.
802802
803803
Complete a list value by completing each item in the list with the inner type.
@@ -866,7 +866,7 @@ def complete_abstract_value(
866866
info: GraphQLResolveInfo,
867867
path: ResponsePath,
868868
result: Any,
869-
) -> MaybeAwaitable[Any]:
869+
) -> AwaitableOrValue[Any]:
870870
"""Complete an abstract value.
871871
872872
Complete a value of an abstract type by determining the runtime object type of
@@ -947,7 +947,7 @@ def complete_object_value(
947947
info: GraphQLResolveInfo,
948948
path: ResponsePath,
949949
result: Any,
950-
) -> MaybeAwaitable[Dict[str, Any]]:
950+
) -> AwaitableOrValue[Dict[str, Any]]:
951951
"""Complete an Object value by executing all sub-selections."""
952952
# If there is an `is_type_of()` predicate function, call it with the current
953953
# result. If `is_type_of()` returns False, then raise an error rather than
@@ -981,7 +981,7 @@ def collect_and_execute_subfields(
981981
field_nodes: List[FieldNode],
982982
path: ResponsePath,
983983
result: Any,
984-
) -> MaybeAwaitable[Dict[str, Any]]:
984+
) -> AwaitableOrValue[Dict[str, Any]]:
985985
"""Collect sub-fields to execute to complete this value."""
986986
sub_field_nodes = self.collect_subfields(return_type, field_nodes)
987987
return self.execute_fields(return_type, result, path, sub_field_nodes)
@@ -1100,7 +1100,7 @@ def invalid_return_type_error(
11001100

11011101
def default_type_resolver(
11021102
value: Any, info: GraphQLResolveInfo, abstract_type: GraphQLAbstractType
1103-
) -> MaybeAwaitable[Optional[Union[GraphQLObjectType, str]]]:
1103+
) -> AwaitableOrValue[Optional[Union[GraphQLObjectType, str]]]:
11041104
"""Default type resolver function.
11051105
11061106
If a resolve_type function is not given, then a default resolve behavior is used

graphql/execution/middleware.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ class MiddlewareManager:
1616
If middleware is provided as an object, it must provide a method `resolve` that is
1717
used as the middleware function.
1818
19-
Note that since resolvers return "MaybeAwaitable" values, all middleware functions
19+
Note that since resolvers return "AwaitableOrValue"s, all middleware functions
2020
must be aware of this and check whether values are awaitable before awaiting them.
2121
"""
2222

graphql/graphql.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
from .error import GraphQLError
66
from .execution import execute, ExecutionResult, ExecutionContext, Middleware
77
from .language import parse, Source
8-
from .pyutils import MaybeAwaitable
8+
from .pyutils import AwaitableOrValue
99
from .type import (
1010
GraphQLFieldResolver,
1111
GraphQLSchema,
@@ -141,7 +141,7 @@ def graphql_impl(
141141
type_resolver,
142142
middleware,
143143
execution_context_class,
144-
) -> MaybeAwaitable[ExecutionResult]:
144+
) -> AwaitableOrValue[ExecutionResult]:
145145
"""Execute a query, return asynchronously only if necessary."""
146146
# Validate Schema
147147
schema_validation_errors = validate_schema(schema)

graphql/pyutils/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
from .is_integer import is_integer
1818
from .is_invalid import is_invalid
1919
from .is_nullish import is_nullish
20-
from .maybe_awaitable import MaybeAwaitable
20+
from .awaitable_or_value import AwaitableOrValue
2121
from .or_list import or_list
2222
from .quoted_or_list import quoted_or_list
2323
from .suggestion_list import suggestion_list
@@ -34,7 +34,7 @@
3434
"is_integer",
3535
"is_invalid",
3636
"is_nullish",
37-
"MaybeAwaitable",
37+
"AwaitableOrValue",
3838
"or_list",
3939
"quoted_or_list",
4040
"suggestion_list",

graphql/pyutils/awaitable_or_value.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
from typing import Awaitable, TypeVar, Union
2+
3+
__all__ = ["AwaitableOrValue"]
4+
5+
6+
T = TypeVar("T")
7+
8+
AwaitableOrValue = Union[Awaitable[T], T]

graphql/pyutils/maybe_awaitable.py

Lines changed: 0 additions & 8 deletions
This file was deleted.

graphql/type/definition.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
UnionTypeExtensionNode,
4343
ValueNode,
4444
)
45-
from ..pyutils import MaybeAwaitable, cached_property, inspect
45+
from ..pyutils import AwaitableOrValue, cached_property, inspect
4646
from ..utilities.value_from_ast_untyped import value_from_ast_untyped
4747

4848
if TYPE_CHECKING: # pragma: no cover
@@ -513,12 +513,12 @@ class GraphQLResolveInfo(NamedTuple):
513513
# the context is passed as part of the GraphQLResolveInfo:
514514
GraphQLTypeResolver = Callable[
515515
[Any, GraphQLResolveInfo, "GraphQLAbstractType"],
516-
MaybeAwaitable[Optional[Union["GraphQLObjectType", str]]],
516+
AwaitableOrValue[Optional[Union["GraphQLObjectType", str]]],
517517
]
518518

519519
# Note: Contrary to the Javascript implementation of GraphQLIsTypeOfFn,
520520
# the context is passed as part of the GraphQLResolveInfo:
521-
GraphQLIsTypeOfFn = Callable[[Any, GraphQLResolveInfo], MaybeAwaitable[bool]]
521+
GraphQLIsTypeOfFn = Callable[[Any, GraphQLResolveInfo], AwaitableOrValue[bool]]
522522

523523

524524
class GraphQLArgument:

0 commit comments

Comments
 (0)