Skip to content

Commit 5b9a728

Browse files
committed
Add named input and output types
Unfortunately, we cannot use these for overloading since they overlap. Replicates graphql/graphql-js@9ba6b17
1 parent b303065 commit 5b9a728

File tree

3 files changed

+56
-34
lines changed

3 files changed

+56
-34
lines changed

Diff for: src/graphql/__init__.py

+4
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,8 @@
142142
GraphQLWrappingType,
143143
GraphQLNullableType,
144144
GraphQLNamedType,
145+
GraphQLNamedInputType,
146+
GraphQLNamedOutputType,
145147
ThunkCollection,
146148
ThunkMapping,
147149
GraphQLArgument,
@@ -505,6 +507,8 @@
505507
"GraphQLWrappingType",
506508
"GraphQLNullableType",
507509
"GraphQLNamedType",
510+
"GraphQLNamedInputType",
511+
"GraphQLNamedOutputType",
508512
"ThunkCollection",
509513
"ThunkMapping",
510514
"GraphQLArgument",

Diff for: src/graphql/type/__init__.py

+4
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,8 @@
7676
GraphQLWrappingType,
7777
GraphQLNullableType,
7878
GraphQLNamedType,
79+
GraphQLNamedInputType,
80+
GraphQLNamedOutputType,
7981
ThunkCollection,
8082
ThunkMapping,
8183
GraphQLArgument,
@@ -204,6 +206,8 @@
204206
"GraphQLWrappingType",
205207
"GraphQLNullableType",
206208
"GraphQLNamedType",
209+
"GraphQLNamedInputType",
210+
"GraphQLNamedOutputType",
207211
"ThunkCollection",
208212
"ThunkMapping",
209213
"GraphQLArgument",

Diff for: src/graphql/type/definition.py

+48-34
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,8 @@
118118
"GraphQLLeafType",
119119
"GraphQLList",
120120
"GraphQLNamedType",
121+
"GraphQLNamedInputType",
122+
"GraphQLNamedOutputType",
121123
"GraphQLNullableType",
122124
"GraphQLNonNull",
123125
"GraphQLResolveInfo",
@@ -188,9 +190,6 @@ def assert_wrapping_type(type_: Any) -> GraphQLWrappingType:
188190
return cast(GraphQLWrappingType, type_)
189191

190192

191-
# These named types do not include modifiers like List or NonNull.
192-
193-
194193
class GraphQLNamedType(GraphQLType):
195194
"""Base class for all GraphQL named types"""
196195

@@ -258,37 +257,6 @@ def __copy__(self) -> "GraphQLNamedType": # pragma: no cover
258257
return self.__class__(**self.to_kwargs())
259258

260259

261-
def is_named_type(type_: Any) -> bool:
262-
return isinstance(type_, GraphQLNamedType)
263-
264-
265-
def assert_named_type(type_: Any) -> GraphQLNamedType:
266-
if not is_named_type(type_):
267-
raise TypeError(f"Expected {type_} to be a GraphQL named type.")
268-
return cast(GraphQLNamedType, type_)
269-
270-
271-
@overload
272-
def get_named_type(type_: None) -> None:
273-
...
274-
275-
276-
@overload
277-
def get_named_type(type_: GraphQLType) -> GraphQLNamedType:
278-
...
279-
280-
281-
def get_named_type(type_: Optional[GraphQLType]) -> Optional[GraphQLNamedType]:
282-
"""Unwrap possible wrapping type"""
283-
if type_:
284-
unwrapped_type = type_
285-
while is_wrapping_type(unwrapped_type):
286-
unwrapped_type = cast(GraphQLWrappingType, unwrapped_type)
287-
unwrapped_type = unwrapped_type.of_type
288-
return cast(GraphQLNamedType, unwrapped_type)
289-
return None
290-
291-
292260
T = TypeVar("T")
293261

294262
ThunkCollection = Union[Callable[[], Collection[T]], Collection[T]]
@@ -1678,6 +1646,52 @@ def assert_output_type(type_: Any) -> GraphQLOutputType:
16781646
return cast(GraphQLOutputType, type_)
16791647

16801648

1649+
# These named types do not include modifiers like List or NonNull.
1650+
1651+
GraphQLNamedInputType = Union[
1652+
GraphQLScalarType, GraphQLEnumType, GraphQLInputObjectType
1653+
]
1654+
1655+
GraphQLNamedOutputType = Union[
1656+
GraphQLScalarType,
1657+
GraphQLObjectType,
1658+
GraphQLInterfaceType,
1659+
GraphQLUnionType,
1660+
GraphQLEnumType,
1661+
]
1662+
1663+
1664+
def is_named_type(type_: Any) -> bool:
1665+
return isinstance(type_, GraphQLNamedType)
1666+
1667+
1668+
def assert_named_type(type_: Any) -> GraphQLNamedType:
1669+
if not is_named_type(type_):
1670+
raise TypeError(f"Expected {type_} to be a GraphQL named type.")
1671+
return cast(GraphQLNamedType, type_)
1672+
1673+
1674+
@overload
1675+
def get_named_type(type_: None) -> None:
1676+
...
1677+
1678+
1679+
@overload
1680+
def get_named_type(type_: GraphQLType) -> GraphQLNamedType:
1681+
...
1682+
1683+
1684+
def get_named_type(type_: Optional[GraphQLType]) -> Optional[GraphQLNamedType]:
1685+
"""Unwrap possible wrapping type"""
1686+
if type_:
1687+
unwrapped_type = type_
1688+
while is_wrapping_type(unwrapped_type):
1689+
unwrapped_type = cast(GraphQLWrappingType, unwrapped_type)
1690+
unwrapped_type = unwrapped_type.of_type
1691+
return cast(GraphQLNamedType, unwrapped_type)
1692+
return None
1693+
1694+
16811695
# These types may describe types which may be leaf values.
16821696

16831697
graphql_leaf_types = (GraphQLScalarType, GraphQLEnumType)

0 commit comments

Comments
 (0)