Handle relay connection field being required

This commit is contained in:
Jonathan Kim 2018-02-17 20:18:55 +00:00
parent 42c96a453f
commit 38baf7ab52

View File

@ -99,7 +99,10 @@ class IterableConnectionField(Field):
def type(self): def type(self):
type = super(IterableConnectionField, self).type type = super(IterableConnectionField, self).type
connection_type = type connection_type = type
if is_node(type): if isinstance(type, NonNull):
connection_type = type.of_type
if is_node(connection_type):
raise Exception( raise Exception(
"ConnectionField's now need a explicit ConnectionType for Nodes.\n" "ConnectionField's now need a explicit ConnectionType for Nodes.\n"
"Read more: https://github.com/graphql-python/graphene/blob/v2.0.0/UPGRADE-v2.0.md#node-connections" "Read more: https://github.com/graphql-python/graphene/blob/v2.0.0/UPGRADE-v2.0.md#node-connections"
@ -108,10 +111,13 @@ class IterableConnectionField(Field):
assert issubclass(connection_type, Connection), ( assert issubclass(connection_type, Connection), (
'{} type have to be a subclass of Connection. Received "{}".' '{} type have to be a subclass of Connection. Received "{}".'
).format(self.__class__.__name__, connection_type) ).format(self.__class__.__name__, connection_type)
return connection_type return type
@classmethod @classmethod
def resolve_connection(cls, connection_type, args, resolved): def resolve_connection(cls, connection_type, args, resolved):
if isinstance(connection_type, NonNull):
connection_type = connection_type.of_type
if isinstance(resolved, connection_type): if isinstance(resolved, connection_type):
return resolved return resolved