mirror of
https://github.com/graphql-python/graphene.git
synced 2025-02-02 20:54:16 +03:00
Simplified Node type
This commit is contained in:
parent
7a6d741531
commit
a023aeba62
|
@ -1,3 +1,4 @@
|
||||||
|
from collections import OrderedDict
|
||||||
from functools import partial
|
from functools import partial
|
||||||
|
|
||||||
import six
|
import six
|
||||||
|
@ -58,15 +59,21 @@ class NodeField(Field):
|
||||||
return partial(self.node_type.node_resolver, only_type=get_type(self.field_type))
|
return partial(self.node_type.node_resolver, only_type=get_type(self.field_type))
|
||||||
|
|
||||||
|
|
||||||
class Node(Interface):
|
class AbstractNode(Interface):
|
||||||
'''An object with an ID'''
|
class Meta:
|
||||||
|
abstract = True
|
||||||
|
|
||||||
|
@classmethod
|
||||||
def __init_subclass_with_meta__(cls, **options):
|
def __init_subclass_with_meta__(cls, **options):
|
||||||
_meta = InterfaceOptions(cls)
|
_meta = InterfaceOptions(cls)
|
||||||
_meta.fields = {
|
_meta.fields = OrderedDict(
|
||||||
'id': GlobalID(cls, description='The ID of the object.')
|
id=GlobalID(cls, description='The ID of the object.')
|
||||||
}
|
)
|
||||||
super(Node, cls).__init_subclass_with_meta__(cls, _meta=_meta, **options)
|
super(AbstractNode, cls).__init_subclass_with_meta__(_meta=_meta, **options)
|
||||||
|
|
||||||
|
|
||||||
|
class Node(AbstractNode):
|
||||||
|
'''An object with an ID'''
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def Field(cls, *args, **kwargs): # noqa: N802
|
def Field(cls, *args, **kwargs): # noqa: N802
|
||||||
|
|
|
@ -2,12 +2,12 @@ from collections import OrderedDict
|
||||||
|
|
||||||
from graphql_relay import to_global_id
|
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 ..connection import Connection
|
||||||
from ..node import Node
|
from ..node import Node
|
||||||
|
|
||||||
|
|
||||||
class SharedNodeFields(AbstractType):
|
class SharedNodeFields(object):
|
||||||
|
|
||||||
shared = String()
|
shared = String()
|
||||||
something_else = String()
|
something_else = String()
|
||||||
|
@ -54,15 +54,6 @@ def test_node_good():
|
||||||
assert 'id' in MyNode._meta.fields
|
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():
|
def test_node_query():
|
||||||
executed = schema.execute(
|
executed = schema.execute(
|
||||||
'{ node(id:"%s") { ... on MyNode { name } } }' % Node.to_global_id("MyNode", 1)
|
'{ node(id:"%s") { ... on MyNode { name } } }' % Node.to_global_id("MyNode", 1)
|
||||||
|
|
|
@ -19,7 +19,9 @@ class Interface(BaseType):
|
||||||
when the field is resolved.
|
when the field is resolved.
|
||||||
'''
|
'''
|
||||||
@classmethod
|
@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:
|
if not _meta:
|
||||||
_meta = InterfaceOptions(cls)
|
_meta = InterfaceOptions(cls)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user