mirror of
https://github.com/graphql-python/graphene.git
synced 2025-02-02 12:44:15 +03:00
Improved ConnectionField exception message. Fixed #356
This commit is contained in:
parent
0efee6be5d
commit
bb7976a75f
|
@ -115,7 +115,7 @@ class IterableConnectionField(Field):
|
||||||
connection_type = type
|
connection_type = type
|
||||||
assert issubclass(connection_type, Connection), (
|
assert issubclass(connection_type, Connection), (
|
||||||
'{} type have to be a subclass of Connection. Received "{}".'
|
'{} type have to be a subclass of Connection. Received "{}".'
|
||||||
).format(str(self), connection_type)
|
).format(self.__class__.__name__, connection_type)
|
||||||
return connection_type
|
return connection_type
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
|
|
|
@ -12,9 +12,9 @@ def is_node(objecttype):
|
||||||
'''
|
'''
|
||||||
Check if the given objecttype has Node as an interface
|
Check if the given objecttype has Node as an interface
|
||||||
'''
|
'''
|
||||||
assert issubclass(objecttype, ObjectType), (
|
if not issubclass(objecttype, ObjectType):
|
||||||
'Only ObjectTypes can have a Node interface. Received %s'
|
return False
|
||||||
) % objecttype
|
|
||||||
for i in objecttype._meta.interfaces:
|
for i in objecttype._meta.interfaces:
|
||||||
if issubclass(i, Node):
|
if issubclass(i, Node):
|
||||||
return True
|
return True
|
||||||
|
|
24
graphene/tests/issues/test_356.py
Normal file
24
graphene/tests/issues/test_356.py
Normal 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".'
|
Loading…
Reference in New Issue
Block a user