Skip to content

Commit bb7976a

Browse files
committed
Improved ConnectionField exception message. Fixed #356
1 parent 0efee6b commit bb7976a

File tree

3 files changed

+28
-4
lines changed

3 files changed

+28
-4
lines changed

graphene/relay/connection.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ def type(self):
115115
connection_type = type
116116
assert issubclass(connection_type, Connection), (
117117
'{} type have to be a subclass of Connection. Received "{}".'
118-
).format(str(self), connection_type)
118+
).format(self.__class__.__name__, connection_type)
119119
return connection_type
120120

121121
@classmethod

graphene/relay/node.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@ def is_node(objecttype):
1212
'''
1313
Check if the given objecttype has Node as an interface
1414
'''
15-
assert issubclass(objecttype, ObjectType), (
16-
'Only ObjectTypes can have a Node interface. Received %s'
17-
) % objecttype
15+
if not issubclass(objecttype, ObjectType):
16+
return False
17+
1818
for i in objecttype._meta.interfaces:
1919
if issubclass(i, Node):
2020
return True

graphene/tests/issues/test_356.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# https://github.com/graphql-python/graphene/issues/356
2+
3+
import pytest
4+
import graphene
5+
from graphene import relay
6+
7+
class SomeTypeOne(graphene.ObjectType):
8+
pass
9+
10+
class SomeTypeTwo(graphene.ObjectType):
11+
pass
12+
13+
class MyUnion(graphene.Union):
14+
class Meta:
15+
types = (SomeTypeOne, SomeTypeTwo)
16+
17+
def test_issue():
18+
with pytest.raises(Exception) as exc_info:
19+
class Query(graphene.ObjectType):
20+
things = relay.ConnectionField(MyUnion)
21+
22+
schema = graphene.Schema(query=Query)
23+
24+
assert str(exc_info.value) == 'IterableConnectionField type have to be a subclass of Connection. Received "MyUnion".'

0 commit comments

Comments
 (0)