Skip to content

Commit aee9b79

Browse files
committed
Add missing repr to GraphQLList and GraphQLNonNull
Replicates graphql/graphql-js@55c03fb
1 parent b7c095b commit aee9b79

File tree

2 files changed

+23
-12
lines changed

2 files changed

+23
-12
lines changed

graphql/type/definition.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,9 @@ def __init__(self, type_: GT) -> None:
164164
)
165165
self.of_type = type_
166166

167+
def __repr__(self):
168+
return f"<{self.__class__.__name__} {self.of_type!r}>"
169+
167170

168171
def is_wrapping_type(type_: Any) -> bool:
169172
return isinstance(type_, GraphQLWrappingType)
@@ -219,12 +222,12 @@ def __init__(
219222
self.ast_node = ast_node
220223
self.extension_ast_nodes = extension_ast_nodes # type: ignore
221224

225+
def __repr__(self):
226+
return f"<{self.__class__.__name__} {self.name!r}>"
227+
222228
def __str__(self):
223229
return self.name
224230

225-
def __repr__(self):
226-
return f"<{self.__class__.__name__}({self})>"
227-
228231
def to_kwargs(self) -> Dict[str, Any]:
229232
return dict(
230233
name=self.name,
@@ -357,12 +360,12 @@ def __init__(
357360
self.parse_value = parse_value or default_value_parser
358361
self.parse_literal = parse_literal or value_from_ast_untyped
359362

363+
def __repr__(self):
364+
return f"<{self.__class__.__name__} {self.name!r}>"
365+
360366
def __str__(self):
361367
return self.name
362368

363-
def __repr__(self):
364-
return f"<{self.__class__.__name__}({self})>"
365-
366369
def to_kwargs(self) -> Dict[str, Any]:
367370
return dict(
368371
**super().to_kwargs(),

tests/type/test_definition.py

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -678,9 +678,17 @@ def stringifies_simple_types():
678678
assert str(GraphQLList(ListOfScalarsType)) == "[[Scalar]]"
679679

680680
def simple_types_have_repr():
681-
assert repr(ScalarType) == "<GraphQLScalarType(Scalar)>"
682-
assert repr(ObjectType) == "<GraphQLObjectType(Object)>"
683-
assert repr(InterfaceType) == "<GraphQLInterfaceType(Interface)>"
684-
assert repr(UnionType) == "<GraphQLUnionType(Union)>"
685-
assert repr(EnumType) == "<GraphQLEnumType(Enum)>"
686-
assert repr(InputObjectType) == "<GraphQLInputObjectType(InputObject)>"
681+
assert repr(ScalarType) == "<GraphQLScalarType 'Scalar'>"
682+
assert repr(ObjectType) == "<GraphQLObjectType 'Object'>"
683+
assert repr(InterfaceType) == "<GraphQLInterfaceType 'Interface'>"
684+
assert repr(UnionType) == "<GraphQLUnionType 'Union'>"
685+
assert repr(EnumType) == "<GraphQLEnumType 'Enum'>"
686+
assert repr(InputObjectType) == "<GraphQLInputObjectType 'InputObject'>"
687+
assert (
688+
repr(ListOfNonNullScalarsType)
689+
== "<GraphQLList <GraphQLNonNull <GraphQLScalarType 'Scalar'>>>"
690+
)
691+
assert (
692+
repr(GraphQLList(ListOfScalarsType))
693+
== "<GraphQLList <GraphQLList <GraphQLScalarType 'Scalar'>>>"
694+
)

0 commit comments

Comments
 (0)