Updated to work with last version of graphql-relay

This commit is contained in:
Syrus Akbary 2015-10-10 00:09:14 -07:00
parent ea95ca2b0c
commit 4e8fd488ff
5 changed files with 19 additions and 19 deletions

View File

@ -1,5 +1,5 @@
from graphql_relay.node.node import ( from graphql_relay.node.node import (
globalIdField global_id_field
) )
from graphene import signals from graphene import signals

View File

@ -1,14 +1,14 @@
from collections import Iterable, OrderedDict from collections import Iterable, OrderedDict
from graphql_relay.connection.arrayconnection import ( from graphql_relay.connection.arrayconnection import (
connectionFromArray connection_from_list
) )
from graphql_relay.connection.connection import ( from graphql_relay.connection.connection import (
connectionArgs connectionArgs
) )
from graphql_relay.node.node import ( from graphql_relay.node.node import (
globalIdField, global_id_field,
fromGlobalId from_global_id
) )
from graphene.core.fields import Field, LazyNativeField, LazyField from graphene.core.fields import Field, LazyNativeField, LazyField
@ -31,7 +31,7 @@ class ConnectionField(Field):
resolved = self.wrap_resolved(resolved, instance, args, info) resolved = self.wrap_resolved(resolved, instance, args, info)
assert isinstance( assert isinstance(
resolved, Iterable), 'Resolved value from the connection field have to be iterable' resolved, Iterable), 'Resolved value from the connection field have to be iterable'
return connectionFromArray(resolved, args) return connection_from_list(resolved, args)
@memoize @memoize
def internal_type(self, schema): def internal_type(self, schema):
@ -53,7 +53,7 @@ class NodeField(LazyNativeField):
field.contribute_to_class(self.object_type, self.field_name) field.contribute_to_class(self.object_type, self.field_name)
return field.internal_field(schema) return field.internal_field(schema)
from graphene.relay.types import BaseNode from graphene.relay.types import BaseNode
return BaseNode.get_definitions(schema).nodeField return BaseNode.get_definitions(schema).node_field
class NodeTypeField(LazyField): class NodeTypeField(LazyField):
@ -63,11 +63,11 @@ class NodeTypeField(LazyField):
def inner_field(self, schema): def inner_field(self, schema):
from graphene.relay.types import BaseNode from graphene.relay.types import BaseNode
node_field = BaseNode.get_definitions(schema).nodeField node_field = BaseNode.get_definitions(schema).node_field
def resolver(instance, args, info): def resolver(instance, args, info):
global_id = args.get('id') global_id = args.get('id')
resolved_global_id = fromGlobalId(global_id) resolved_global_id = from_global_id(global_id)
if resolved_global_id.type == self.field_object_type._meta.type_name: if resolved_global_id.type == self.field_object_type._meta.type_name:
return node_field.resolver(instance, args, info) return node_field.resolver(instance, args, info)
@ -80,4 +80,4 @@ class NodeTypeField(LazyField):
class NodeIDField(LazyNativeField): class NodeIDField(LazyNativeField):
def get_field(self, schema): def get_field(self, schema):
return globalIdField(self.object_type._meta.type_name) return global_id_field(self.object_type._meta.type_name)

View File

@ -1,9 +1,9 @@
from graphql_relay.node.node import ( from graphql_relay.node.node import (
nodeDefinitions, node_definitions,
fromGlobalId from_global_id
) )
from graphql_relay.connection.connection import ( from graphql_relay.connection.connection import (
connectionDefinitions connection_definitions
) )
from graphene.core.types import Interface from graphene.core.types import Interface
@ -16,7 +16,7 @@ def get_node_type(schema, obj):
def get_node(schema, globalId, *args): def get_node(schema, globalId, *args):
resolvedGlobalId = fromGlobalId(globalId) resolvedGlobalId = from_global_id(globalId)
_type, _id = resolvedGlobalId.type, resolvedGlobalId.id _type, _id = resolvedGlobalId.type, resolvedGlobalId.id
object_type = schema.get_type(_type) object_type = schema.get_type(_type)
if not object_type or not issubclass(object_type, BaseNode): if not object_type or not issubclass(object_type, BaseNode):
@ -29,22 +29,22 @@ class BaseNode(object):
@classmethod @classmethod
@memoize @memoize
def get_definitions(cls, schema): def get_definitions(cls, schema):
return nodeDefinitions(lambda *args: get_node(schema, *args), lambda *args: get_node_type(schema, *args)) return node_definitions(lambda *args: get_node(schema, *args), lambda *args: get_node_type(schema, *args))
@classmethod @classmethod
@memoize @memoize
def get_connection(cls, schema): def get_connection(cls, schema):
_type = cls.internal_type(schema) _type = cls.internal_type(schema)
type_name = cls._meta.type_name type_name = cls._meta.type_name
connection = connectionDefinitions(type_name, _type).connectionType connection = connection_definitions(type_name, _type).connection_type
return connection return connection
@classmethod @classmethod
def internal_type(cls, schema): def internal_type(cls, schema):
from graphene.relay.utils import is_node_type from graphene.relay.utils import is_node_type
if is_node_type(cls): if is_node_type(cls):
# Return only nodeInterface when is the Node Inerface # Return only node_interface when is the Node Inerface
return BaseNode.get_definitions(schema).nodeInterface return BaseNode.get_definitions(schema).node_interface
return super(BaseNode, cls).internal_type(schema) return super(BaseNode, cls).internal_type(schema)

View File

@ -57,7 +57,7 @@ setup(
'six', 'six',
'blinker', 'blinker',
'graphql-core==0.1a2', 'graphql-core==0.1a2',
'graphql-relay==0.1.4' 'graphql-relay==0.2.0'
], ],
tests_require=[ tests_require=[
'pytest>=2.7.2', 'pytest>=2.7.2',

View File

@ -7,7 +7,7 @@ deps=
django>=1.8.0,<1.9 django>=1.8.0,<1.9
pytest-django pytest-django
graphql-core==0.1a0 graphql-core==0.1a0
graphql-relay==0.1.3 graphql-relay==0.2.0
flake8 flake8
six six
blinker blinker