Allow the connection node to be wrapped in a NonNull type (#934)

This commit is contained in:
Minh Tu Le 2019-04-12 16:29:53 -07:00 committed by Eran Kampf
parent daf0d17647
commit abff3d75a3
2 changed files with 12 additions and 1 deletions

View File

@ -53,7 +53,7 @@ class Connection(ObjectType):
def __init_subclass_with_meta__(cls, node=None, name=None, **options): def __init_subclass_with_meta__(cls, node=None, name=None, **options):
_meta = ConnectionOptions(cls) _meta = ConnectionOptions(cls)
assert node, "You have to provide a node in {}.Meta".format(cls.__name__) assert node, "You have to provide a node in {}.Meta".format(cls.__name__)
assert issubclass( assert isinstance(node, NonNull) or issubclass(
node, (Scalar, Enum, ObjectType, Interface, Union, NonNull) node, (Scalar, Enum, ObjectType, Interface, Union, NonNull)
), ('Received incompatible node "{}" for Connection {}.').format( ), ('Received incompatible node "{}" for Connection {}.').format(
node, cls.__name__ node, cls.__name__

View File

@ -108,6 +108,17 @@ def test_edge_with_bases():
assert edge_fields["other"].type == String assert edge_fields["other"].type == String
def test_edge_with_nonnull_node():
class MyObjectConnection(Connection):
class Meta:
node = NonNull(MyObject)
edge_fields = MyObjectConnection.Edge._meta.fields
assert isinstance(edge_fields["node"], Field)
assert isinstance(edge_fields["node"].type, NonNull)
assert edge_fields["node"].type.of_type == MyObject
def test_pageinfo(): def test_pageinfo():
assert PageInfo._meta.name == "PageInfo" assert PageInfo._meta.name == "PageInfo"
fields = PageInfo._meta.fields fields = PageInfo._meta.fields