Improved ConnectionField exception message. Fixed #356

This commit is contained in:
Syrus Akbary 2016-11-14 20:27:06 -08:00
parent 0efee6be5d
commit bb7976a75f
3 changed files with 28 additions and 4 deletions

View File

@ -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

View File

@ -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

View File

@ -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".'