From a023aeba627f2d49a3237efc7302c1933efe4ff1 Mon Sep 17 00:00:00 2001 From: Syrus Akbary Date: Wed, 12 Jul 2017 01:57:15 -0700 Subject: [PATCH] Simplified Node type --- graphene/relay/node.py | 19 +++++++++++++------ graphene/relay/tests/test_node.py | 13 ++----------- graphene/types/interface.py | 4 +++- 3 files changed, 18 insertions(+), 18 deletions(-) diff --git a/graphene/relay/node.py b/graphene/relay/node.py index b129adbf..33a2628d 100644 --- a/graphene/relay/node.py +++ b/graphene/relay/node.py @@ -1,3 +1,4 @@ +from collections import OrderedDict from functools import partial import six @@ -58,15 +59,21 @@ class NodeField(Field): return partial(self.node_type.node_resolver, only_type=get_type(self.field_type)) -class Node(Interface): - '''An object with an ID''' +class AbstractNode(Interface): + class Meta: + abstract = True + @classmethod def __init_subclass_with_meta__(cls, **options): _meta = InterfaceOptions(cls) - _meta.fields = { - 'id': GlobalID(cls, description='The ID of the object.') - } - super(Node, cls).__init_subclass_with_meta__(cls, _meta=_meta, **options) + _meta.fields = OrderedDict( + id=GlobalID(cls, description='The ID of the object.') + ) + super(AbstractNode, cls).__init_subclass_with_meta__(_meta=_meta, **options) + + +class Node(AbstractNode): + '''An object with an ID''' @classmethod def Field(cls, *args, **kwargs): # noqa: N802 diff --git a/graphene/relay/tests/test_node.py b/graphene/relay/tests/test_node.py index 6a9c2e04..9fdaa702 100644 --- a/graphene/relay/tests/test_node.py +++ b/graphene/relay/tests/test_node.py @@ -2,12 +2,12 @@ from collections import OrderedDict from graphql_relay import to_global_id -from ...types import AbstractType, ObjectType, Schema, String +from ...types import ObjectType, Schema, String from ..connection import Connection from ..node import Node -class SharedNodeFields(AbstractType): +class SharedNodeFields(object): shared = String() something_else = String() @@ -54,15 +54,6 @@ def test_node_good(): assert 'id' in MyNode._meta.fields -def test_node_get_connection(): - connection = MyNode.Connection - assert issubclass(connection, Connection) - - -def test_node_get_connection_dont_duplicate(): - assert MyNode.Connection == MyNode.Connection - - def test_node_query(): executed = schema.execute( '{ node(id:"%s") { ... on MyNode { name } } }' % Node.to_global_id("MyNode", 1) diff --git a/graphene/types/interface.py b/graphene/types/interface.py index dc7c34cc..37d38ac1 100644 --- a/graphene/types/interface.py +++ b/graphene/types/interface.py @@ -19,7 +19,9 @@ class Interface(BaseType): when the field is resolved. ''' @classmethod - def __init_subclass_with_meta__(cls, _meta=None, **options): + def __init_subclass_with_meta__(cls, abstract=False, _meta=None, **options): + if abstract: + return if not _meta: _meta = InterfaceOptions(cls)