Skip to content

Commit 9090b6e

Browse files
committed
Make default_resolve_type to match GraphQLTypeResolver type
Replicates graphql/graphql-js@898cf20
1 parent 49b4fce commit 9090b6e

File tree

7 files changed

+14
-17
lines changed

7 files changed

+14
-17
lines changed

graphql/execution/execute.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -860,12 +860,8 @@ def complete_abstract_value(
860860
Complete a value of an abstract type by determining the runtime object type of
861861
that value, then complete the value for that type.
862862
"""
863-
resolve_type = return_type.resolve_type
864-
runtime_type = (
865-
resolve_type(result, info)
866-
if resolve_type
867-
else default_resolve_type_fn(result, info, return_type)
868-
)
863+
resolve_type_fn = return_type.resolve_type or default_resolve_type_fn
864+
runtime_type = resolve_type_fn(result, info, return_type)
869865

870866
if isawaitable(runtime_type):
871867

graphql/type/definition.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -509,7 +509,8 @@ class GraphQLResolveInfo(NamedTuple):
509509
# Note: Contrary to the Javascript implementation of GraphQLTypeResolver,
510510
# the context is passed as part of the GraphQLResolveInfo:
511511
GraphQLTypeResolver = Callable[
512-
[Any, GraphQLResolveInfo], MaybeAwaitable[Union["GraphQLObjectType", str]]
512+
[Any, GraphQLResolveInfo, "GraphQLAbstractType"],
513+
MaybeAwaitable[Optional[Union["GraphQLObjectType", str]]],
513514
]
514515

515516
# Note: Contrary to the Javascript implementation of GraphQLIsTypeOfFn,

tests/execution/test_abstract.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ def is_type_of(obj, _info):
3939

4040

4141
def get_type_resolver(types):
42-
def resolve(obj, _info):
42+
def resolve(obj, _info, _type):
4343
return resolve_thunk(types).get(obj.__class__)
4444

4545
return resolve

tests/execution/test_abstract_async.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ async def is_type_of(obj, _info):
4545

4646

4747
def get_type_resolver(types):
48-
async def resolve(obj, _info):
48+
async def resolve(obj, _info, _type):
4949
return resolve_thunk(types).get(obj.__class__)
5050

5151
return resolve

tests/execution/test_union_interface.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ class Person(NamedTuple):
5050
)
5151

5252

53-
def resolve_pet_type(value, info):
53+
def resolve_pet_type(value, _info, _type):
5454
if isinstance(value, Dog):
5555
return DogType
5656
if isinstance(value, Cat):
@@ -67,7 +67,7 @@ def resolve_pet_type(value, info):
6767
"friends": GraphQLField(GraphQLList(NamedType)),
6868
},
6969
interfaces=[NamedType],
70-
is_type_of=lambda value, info: isinstance(value, Person),
70+
is_type_of=lambda value, _info: isinstance(value, Person),
7171
)
7272

7373
schema = GraphQLSchema(PersonType, types=[PetType])
@@ -312,7 +312,7 @@ def allows_fragment_conditions_to_be_abstract_types():
312312
def gets_execution_info_in_resolver():
313313
encountered = {}
314314

315-
def resolve_type(obj, info):
315+
def resolve_type(_obj, info, _type):
316316
encountered["context"] = info.context
317317
encountered["schema"] = info.schema
318318
encountered["root_value"] = info.root_value

tests/star_wars_schema.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@
110110
GraphQLString, description="All secrets about their past."
111111
),
112112
},
113-
resolve_type=lambda character, _info: {
113+
resolve_type=lambda character, _info, _type: {
114114
"Human": human_type,
115115
"Droid": droid_type,
116116
}.get(character.type),

tests/validation/harness.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@
7777
),
7878
},
7979
interfaces=[Being, Pet, Canine],
80-
is_type_of=lambda: True,
80+
is_type_of=lambda *_args: True,
8181
)
8282

8383
Cat = GraphQLObjectType(
@@ -90,7 +90,7 @@
9090
"nickname": GraphQLField(GraphQLString),
9191
},
9292
interfaces=[Being, Pet],
93-
is_type_of=lambda: True,
93+
is_type_of=lambda *_args: True,
9494
)
9595

9696
CatOrDog = GraphQLUnionType("CatOrDog", [Dog, Cat])
@@ -100,7 +100,7 @@
100100
Human = GraphQLObjectType(
101101
name="Human",
102102
interfaces=[Being, Intelligent],
103-
is_type_of=lambda: True,
103+
is_type_of=lambda *_args: True,
104104
fields={
105105
"name": GraphQLField(
106106
GraphQLString, {"surname": GraphQLArgument(GraphQLBoolean)}
@@ -112,7 +112,7 @@
112112

113113
Alien = GraphQLObjectType(
114114
name="Alien",
115-
is_type_of=lambda: True,
115+
is_type_of=lambda *_args: True,
116116
interfaces=[Being, Intelligent],
117117
fields={
118118
"iq": GraphQLField(GraphQLInt),

0 commit comments

Comments
 (0)