diff --git a/graphene/relay/connection.py b/graphene/relay/connection.py index 950a103b..691919ca 100644 --- a/graphene/relay/connection.py +++ b/graphene/relay/connection.py @@ -1,12 +1,9 @@ import re -import copy -from functools import partial +from collections import Iterable import six -from graphql_relay import connection_definitions +from graphql_relay import connection_definitions, connection_from_list from ..types.field import Field -from ..types.mutation import Mutation, MutationMeta -from ..types.interface import GrapheneInterfaceType, Interface, InterfaceTypeMeta from ..types.objecttype import ObjectType, ObjectTypeMeta from ..utils.props import props @@ -47,14 +44,36 @@ class ConnectionMeta(ObjectTypeMeta): edge_fields=edge_fields, connection_fields=local_fields, ) + cls.Edge = type(edge.name, (ObjectType, ), {'Meta': type('Meta', (object,), {'graphql_type': edge})}) cls._meta.graphql_type = connection return cls - class Connection(six.with_metaclass(ConnectionMeta, ObjectType)): class Meta: abstract = True resolve_node = None resolve_cursor = None + + +class IterableConnectionField(Field): + # def __init__(self, type, *args, **kwargs): + # if + + def resolver(self, root, args, context, info): + iterable = super(ConnectionField, self).resolver(root, args, context, info) + # if isinstance(resolved, self.type.graphene) + assert isinstance( + iterable, Iterable), 'Resolved value from the connection field have to be iterable' + connection = connection_from_list( + iterable, + args, + connection_type=None, + edge_type=None, + pageinfo_type=None + ) + return connection + + +ConnectionField = IterableConnectionField diff --git a/graphene/relay/mutation.py b/graphene/relay/mutation.py index b5ab4c3c..dde96fff 100644 --- a/graphene/relay/mutation.py +++ b/graphene/relay/mutation.py @@ -1,12 +1,10 @@ from functools import partial -import copy import six from graphql_relay import mutation_with_client_mutation_id from ..types.mutation import Mutation, MutationMeta -from ..types.inputobjecttype import GrapheneInputObjectType, InputObjectType -from ..types.objecttype import GrapheneObjectType -from ..types.field import Field, InputField +from ..types.inputobjecttype import InputObjectType +from ..types.field import Field from ..utils.props import props diff --git a/graphene/relay/node.py b/graphene/relay/node.py index 820c5190..de8bd74d 100644 --- a/graphene/relay/node.py +++ b/graphene/relay/node.py @@ -1,11 +1,10 @@ -import copy from functools import partial import six from graphql_relay import node_definitions, from_global_id, to_global_id from ..types.field import Field from ..types.objecttype import ObjectTypeMeta -from ..types.interface import GrapheneInterfaceType, Interface, InterfaceTypeMeta +from ..types.interface import Interface class NodeMeta(ObjectTypeMeta):