mirror of
https://github.com/graphql-python/graphene.git
synced 2024-11-10 19:56:45 +03:00
Updated to work with last version of graphql-relay
This commit is contained in:
parent
ea95ca2b0c
commit
4e8fd488ff
|
@ -1,5 +1,5 @@
|
|||
from graphql_relay.node.node import (
|
||||
globalIdField
|
||||
global_id_field
|
||||
)
|
||||
|
||||
from graphene import signals
|
||||
|
|
|
@ -1,14 +1,14 @@
|
|||
from collections import Iterable, OrderedDict
|
||||
|
||||
from graphql_relay.connection.arrayconnection import (
|
||||
connectionFromArray
|
||||
connection_from_list
|
||||
)
|
||||
from graphql_relay.connection.connection import (
|
||||
connectionArgs
|
||||
)
|
||||
from graphql_relay.node.node import (
|
||||
globalIdField,
|
||||
fromGlobalId
|
||||
global_id_field,
|
||||
from_global_id
|
||||
)
|
||||
|
||||
from graphene.core.fields import Field, LazyNativeField, LazyField
|
||||
|
@ -31,7 +31,7 @@ class ConnectionField(Field):
|
|||
resolved = self.wrap_resolved(resolved, instance, args, info)
|
||||
assert isinstance(
|
||||
resolved, Iterable), 'Resolved value from the connection field have to be iterable'
|
||||
return connectionFromArray(resolved, args)
|
||||
return connection_from_list(resolved, args)
|
||||
|
||||
@memoize
|
||||
def internal_type(self, schema):
|
||||
|
@ -53,7 +53,7 @@ class NodeField(LazyNativeField):
|
|||
field.contribute_to_class(self.object_type, self.field_name)
|
||||
return field.internal_field(schema)
|
||||
from graphene.relay.types import BaseNode
|
||||
return BaseNode.get_definitions(schema).nodeField
|
||||
return BaseNode.get_definitions(schema).node_field
|
||||
|
||||
|
||||
class NodeTypeField(LazyField):
|
||||
|
@ -63,11 +63,11 @@ class NodeTypeField(LazyField):
|
|||
|
||||
def inner_field(self, schema):
|
||||
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):
|
||||
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:
|
||||
return node_field.resolver(instance, args, info)
|
||||
|
||||
|
@ -80,4 +80,4 @@ class NodeTypeField(LazyField):
|
|||
|
||||
class NodeIDField(LazyNativeField):
|
||||
def get_field(self, schema):
|
||||
return globalIdField(self.object_type._meta.type_name)
|
||||
return global_id_field(self.object_type._meta.type_name)
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
from graphql_relay.node.node import (
|
||||
nodeDefinitions,
|
||||
fromGlobalId
|
||||
node_definitions,
|
||||
from_global_id
|
||||
)
|
||||
from graphql_relay.connection.connection import (
|
||||
connectionDefinitions
|
||||
connection_definitions
|
||||
)
|
||||
|
||||
from graphene.core.types import Interface
|
||||
|
@ -16,7 +16,7 @@ def get_node_type(schema, obj):
|
|||
|
||||
|
||||
def get_node(schema, globalId, *args):
|
||||
resolvedGlobalId = fromGlobalId(globalId)
|
||||
resolvedGlobalId = from_global_id(globalId)
|
||||
_type, _id = resolvedGlobalId.type, resolvedGlobalId.id
|
||||
object_type = schema.get_type(_type)
|
||||
if not object_type or not issubclass(object_type, BaseNode):
|
||||
|
@ -29,22 +29,22 @@ class BaseNode(object):
|
|||
@classmethod
|
||||
@memoize
|
||||
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
|
||||
@memoize
|
||||
def get_connection(cls, schema):
|
||||
_type = cls.internal_type(schema)
|
||||
type_name = cls._meta.type_name
|
||||
connection = connectionDefinitions(type_name, _type).connectionType
|
||||
connection = connection_definitions(type_name, _type).connection_type
|
||||
return connection
|
||||
|
||||
@classmethod
|
||||
def internal_type(cls, schema):
|
||||
from graphene.relay.utils import is_node_type
|
||||
if is_node_type(cls):
|
||||
# Return only nodeInterface when is the Node Inerface
|
||||
return BaseNode.get_definitions(schema).nodeInterface
|
||||
# Return only node_interface when is the Node Inerface
|
||||
return BaseNode.get_definitions(schema).node_interface
|
||||
return super(BaseNode, cls).internal_type(schema)
|
||||
|
||||
|
||||
|
|
2
setup.py
2
setup.py
|
@ -57,7 +57,7 @@ setup(
|
|||
'six',
|
||||
'blinker',
|
||||
'graphql-core==0.1a2',
|
||||
'graphql-relay==0.1.4'
|
||||
'graphql-relay==0.2.0'
|
||||
],
|
||||
tests_require=[
|
||||
'pytest>=2.7.2',
|
||||
|
|
Loading…
Reference in New Issue
Block a user