From bb7976a75f2a86313b718f62db6ed624d00bf02d Mon Sep 17 00:00:00 2001 From: Syrus Akbary Date: Mon, 14 Nov 2016 20:27:06 -0800 Subject: [PATCH] Improved ConnectionField exception message. Fixed #356 --- graphene/relay/connection.py | 2 +- graphene/relay/node.py | 6 +++--- graphene/tests/issues/test_356.py | 24 ++++++++++++++++++++++++ 3 files changed, 28 insertions(+), 4 deletions(-) create mode 100644 graphene/tests/issues/test_356.py diff --git a/graphene/relay/connection.py b/graphene/relay/connection.py index 72f018dc..339e4266 100644 --- a/graphene/relay/connection.py +++ b/graphene/relay/connection.py @@ -115,7 +115,7 @@ class IterableConnectionField(Field): connection_type = type assert issubclass(connection_type, Connection), ( '{} type have to be a subclass of Connection. Received "{}".' - ).format(str(self), connection_type) + ).format(self.__class__.__name__, connection_type) return connection_type @classmethod diff --git a/graphene/relay/node.py b/graphene/relay/node.py index 9d795875..3db30e93 100644 --- a/graphene/relay/node.py +++ b/graphene/relay/node.py @@ -12,9 +12,9 @@ def is_node(objecttype): ''' Check if the given objecttype has Node as an interface ''' - assert issubclass(objecttype, ObjectType), ( - 'Only ObjectTypes can have a Node interface. Received %s' - ) % objecttype + if not issubclass(objecttype, ObjectType): + return False + for i in objecttype._meta.interfaces: if issubclass(i, Node): return True diff --git a/graphene/tests/issues/test_356.py b/graphene/tests/issues/test_356.py new file mode 100644 index 00000000..605594e1 --- /dev/null +++ b/graphene/tests/issues/test_356.py @@ -0,0 +1,24 @@ +# https://github.com/graphql-python/graphene/issues/356 + +import pytest +import graphene +from graphene import relay + +class SomeTypeOne(graphene.ObjectType): + pass + +class SomeTypeTwo(graphene.ObjectType): + pass + +class MyUnion(graphene.Union): + class Meta: + types = (SomeTypeOne, SomeTypeTwo) + +def test_issue(): + with pytest.raises(Exception) as exc_info: + class Query(graphene.ObjectType): + things = relay.ConnectionField(MyUnion) + + schema = graphene.Schema(query=Query) + + assert str(exc_info.value) == 'IterableConnectionField type have to be a subclass of Connection. Received "MyUnion".'