Skip to content

Commit

Permalink
Improved ConnectionField exception message. Fixed #356
Browse files Browse the repository at this point in the history
  • Loading branch information
syrusakbary committed Nov 15, 2016
1 parent 0efee6b commit bb7976a
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 4 deletions.
2 changes: 1 addition & 1 deletion graphene/relay/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ def type(self):
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
Expand Down
6 changes: 3 additions & 3 deletions graphene/relay/node.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
24 changes: 24 additions & 0 deletions graphene/tests/issues/test_356.py
Original file line number Diff line number Diff line change
@@ -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".'

0 comments on commit bb7976a

Please sign in to comment.