Improved connection type of checking

This commit is contained in:
Syrus Akbary 2016-11-03 20:21:45 -07:00
parent 42b93b5546
commit 3fa65aa343

View File

@ -95,6 +95,10 @@ class Connection(six.with_metaclass(ConnectionMeta, ObjectType)):
def Field(cls, *args, **kwargs): # noqa: N802
return ConnectionField(cls, *args, **kwargs)
@classmethod
def is_type_of(cls, root, context, info):
return isinstance(root, cls)
@classmethod
def connection_resolver(cls, resolved, args, context, info):
assert isinstance(resolved, Iterable), (
@ -132,7 +136,7 @@ class ConnectionField(Field):
def connection_resolver(cls, resolver, connection_type, root, args, context, info):
resolved = resolver(root, args, context, info)
if isinstance(resolved, connection_type):
if connection_type.is_type_of(resolved, context, info):
return resolved
on_resolve = partial(connection_type.connection_resolver, args=args, context=context, info=info)