Stop requiring get_node in implemented Nodes

This commit is contained in:
Syrus Akbary 2016-08-24 01:15:59 -07:00
parent 241b59dda9
commit 80fb69a9ae
4 changed files with 4 additions and 33 deletions

View File

@ -89,7 +89,9 @@ class Node(six.with_metaclass(NodeMeta, Interface)):
assert cls in graphene_type._meta.interfaces
except:
return None
return graphene_type.get_node(_id, context, info)
get_node = getattr(graphene_type, 'get_node', None)
if get_node:
return get_node(_id, context, info)
@classmethod
def from_global_id(cls, global_id):
@ -101,13 +103,8 @@ class Node(six.with_metaclass(NodeMeta, Interface)):
@classmethod
def implements(cls, objecttype):
require_get_node = cls.get_node_from_global_id == Node.get_node_from_global_id
get_connection = getattr(objecttype, 'get_connection', None)
if not get_connection:
get_connection = partial(get_default_connection, objecttype)
objecttype.Connection = get_connection()
if require_get_node:
assert hasattr(objecttype, 'get_node'), (
'{}.get_node method is required by the Node interface.'
).format(objecttype.__name__)

View File

@ -10,10 +10,6 @@ class MyObject(ObjectType):
interfaces = [Node]
field = String()
@classmethod
def get_node(cls, id):
pass
def test_connection():
class MyObjectConnection(Connection):

View File

@ -11,10 +11,8 @@ letter_chars = ['A', 'B', 'C', 'D', 'E']
class Letter(ObjectType):
class Meta:
interfaces = (Node, )
letter = String()
def get_node(*args, **kwargs):
pass
letter = String()
class Query(ObjectType):

View File

@ -49,26 +49,6 @@ class RootQuery(ObjectType):
schema = Schema(query=RootQuery, types=[MyNode, MyOtherNode])
def test_node_no_get_node():
with pytest.raises(AssertionError) as excinfo:
class MyNode(ObjectType):
class Meta:
interfaces = (Node, )
assert "MyNode.get_node method is required by the Node interface." == str(excinfo.value)
def test_node_no_get_node_with_meta():
with pytest.raises(AssertionError) as excinfo:
class MyNode(ObjectType):
class Meta:
interfaces = (Node, )
assert "MyNode.get_node method is required by the Node interface." == str(excinfo.value)
def test_node_good():
assert 'id' in MyNode._meta.fields