mirror of
https://github.com/graphql-python/graphene.git
synced 2025-02-02 20:54:16 +03:00
Simplified Relay Connection implementation
This commit is contained in:
parent
f3dff38541
commit
8c321875cf
|
@ -10,7 +10,7 @@ from ..types import Boolean, Int, List, String, AbstractType
|
||||||
from ..types.field import Field
|
from ..types.field import Field
|
||||||
from ..types.objecttype import ObjectType, ObjectTypeMeta
|
from ..types.objecttype import ObjectType, ObjectTypeMeta
|
||||||
from ..types.options import Options
|
from ..types.options import Options
|
||||||
from ..types.utils import get_fields_in_type, yank_fields_from_attrs
|
from ..types.utils import merge
|
||||||
from ..utils.is_base_type import is_base_type
|
from ..utils.is_base_type import is_base_type
|
||||||
from ..utils.props import props
|
from ..utils.props import props
|
||||||
from .node import Node, is_node
|
from .node import Node, is_node
|
||||||
|
@ -76,16 +76,16 @@ class ConnectionMeta(ObjectTypeMeta):
|
||||||
if edge_class and issubclass(edge_class, AbstractType):
|
if edge_class and issubclass(edge_class, AbstractType):
|
||||||
edge = type(edge_name, (EdgeBase, edge_class, ObjectType, ), {})
|
edge = type(edge_name, (EdgeBase, edge_class, ObjectType, ), {})
|
||||||
else:
|
else:
|
||||||
edge = type(edge_name, (EdgeBase, ObjectType, ), props(edge_class) if edge_class else {})
|
edge_attrs = props(edge_class) if edge_class else {}
|
||||||
|
edge = type(edge_name, (EdgeBase, ObjectType, ), edge_attrs)
|
||||||
|
|
||||||
cls = ObjectTypeMeta.__new__(cls, name, bases, dict(attrs, _meta=options, Edge=edge))
|
class ConnectionBase(AbstractType):
|
||||||
base_fields = OrderedDict([
|
page_info = Field(PageInfo, name='pageInfo', required=True)
|
||||||
('page_info', Field(PageInfo, name='pageInfo', required=True)),
|
edges = List(edge)
|
||||||
('edges', Field(List(edge)))
|
|
||||||
])
|
bases = (ConnectionBase, ) + bases
|
||||||
base_fields.update(cls._meta.fields)
|
attrs = dict(attrs, _meta=options, Edge=edge)
|
||||||
cls._meta.fields = base_fields
|
return ObjectTypeMeta.__new__(cls, name, bases, attrs)
|
||||||
return cls
|
|
||||||
|
|
||||||
|
|
||||||
class Connection(six.with_metaclass(ConnectionMeta, ObjectType)):
|
class Connection(six.with_metaclass(ConnectionMeta, ObjectType)):
|
||||||
|
|
Loading…
Reference in New Issue
Block a user