Skip to content

Commit a023aeb

Browse files
committed
Simplified Node type
1 parent 7a6d741 commit a023aeb

File tree

3 files changed

+18
-18
lines changed

3 files changed

+18
-18
lines changed

graphene/relay/node.py

+13-6
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
from collections import OrderedDict
12
from functools import partial
23

34
import six
@@ -58,15 +59,21 @@ def get_resolver(self, parent_resolver):
5859
return partial(self.node_type.node_resolver, only_type=get_type(self.field_type))
5960

6061

61-
class Node(Interface):
62-
'''An object with an ID'''
62+
class AbstractNode(Interface):
63+
class Meta:
64+
abstract = True
6365

66+
@classmethod
6467
def __init_subclass_with_meta__(cls, **options):
6568
_meta = InterfaceOptions(cls)
66-
_meta.fields = {
67-
'id': GlobalID(cls, description='The ID of the object.')
68-
}
69-
super(Node, cls).__init_subclass_with_meta__(cls, _meta=_meta, **options)
69+
_meta.fields = OrderedDict(
70+
id=GlobalID(cls, description='The ID of the object.')
71+
)
72+
super(AbstractNode, cls).__init_subclass_with_meta__(_meta=_meta, **options)
73+
74+
75+
class Node(AbstractNode):
76+
'''An object with an ID'''
7077

7178
@classmethod
7279
def Field(cls, *args, **kwargs): # noqa: N802

graphene/relay/tests/test_node.py

+2-11
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@
22

33
from graphql_relay import to_global_id
44

5-
from ...types import AbstractType, ObjectType, Schema, String
5+
from ...types import ObjectType, Schema, String
66
from ..connection import Connection
77
from ..node import Node
88

99

10-
class SharedNodeFields(AbstractType):
10+
class SharedNodeFields(object):
1111

1212
shared = String()
1313
something_else = String()
@@ -54,15 +54,6 @@ def test_node_good():
5454
assert 'id' in MyNode._meta.fields
5555

5656

57-
def test_node_get_connection():
58-
connection = MyNode.Connection
59-
assert issubclass(connection, Connection)
60-
61-
62-
def test_node_get_connection_dont_duplicate():
63-
assert MyNode.Connection == MyNode.Connection
64-
65-
6657
def test_node_query():
6758
executed = schema.execute(
6859
'{ node(id:"%s") { ... on MyNode { name } } }' % Node.to_global_id("MyNode", 1)

graphene/types/interface.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,9 @@ class Interface(BaseType):
1919
when the field is resolved.
2020
'''
2121
@classmethod
22-
def __init_subclass_with_meta__(cls, _meta=None, **options):
22+
def __init_subclass_with_meta__(cls, abstract=False, _meta=None, **options):
23+
if abstract:
24+
return
2325
if not _meta:
2426
_meta = InterfaceOptions(cls)
2527

0 commit comments

Comments
 (0)