Skip to content

Commit eeb9b77

Browse files
committed
GraphQLSchema: simplify get_possible_types & is_possible_type
Replicates graphql/graphql-js@d78b445
1 parent d8e817c commit eeb9b77

File tree

1 file changed

+5
-12
lines changed

1 file changed

+5
-12
lines changed

src/graphql/type/schema.py

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
GraphQLUnionType,
1414
GraphQLInputObjectType,
1515
get_named_type,
16-
is_abstract_type,
1716
is_input_object_type,
1817
is_interface_type,
1918
is_named_type,
@@ -198,8 +197,6 @@ def __init__(
198197
for interface in type_.interfaces:
199198
if is_interface_type(interface):
200199
setdefault(interface.name, []).append(type_)
201-
elif is_abstract_type(type_):
202-
setdefault(type_.name, [])
203200

204201
def to_kwargs(self) -> Dict[str, Any]:
205202
return dict(
@@ -225,20 +222,16 @@ def get_possible_types(
225222
if is_union_type(abstract_type):
226223
abstract_type = cast(GraphQLUnionType, abstract_type)
227224
return abstract_type.types
228-
return self._implementations[abstract_type.name]
225+
return self._implementations[abstract_type.name] or []
229226

230227
def is_possible_type(
231228
self, abstract_type: GraphQLAbstractType, possible_type: GraphQLObjectType
232229
) -> bool:
233230
"""Check whether a concrete type is possible for an abstract type."""
234-
possible_type_map = self._possible_type_map
235-
try:
236-
possible_type_names = possible_type_map[abstract_type.name]
237-
except KeyError:
238-
possible_types = self.get_possible_types(abstract_type)
239-
possible_type_names = {type_.name for type_ in possible_types}
240-
possible_type_map[abstract_type.name] = possible_type_names
241-
return possible_type.name in possible_type_names
231+
return possible_type.name in self._possible_type_map.setdefault(
232+
abstract_type.name,
233+
{type_.name for type_ in self.get_possible_types(abstract_type)},
234+
)
242235

243236
def get_directive(self, name: str) -> Optional[GraphQLDirective]:
244237
for directive in self.directives:

0 commit comments

Comments
 (0)