mirror of
https://github.com/graphql-python/graphene.git
synced 2025-02-09 08:00:39 +03:00
Removed implements check
This commit is contained in:
parent
0f279abecf
commit
27a0d4147f
|
@ -19,17 +19,7 @@ class GrapheneInterfaceType(GrapheneGraphQLType, GraphQLInterfaceType):
|
||||||
|
|
||||||
|
|
||||||
class GrapheneObjectType(GrapheneGraphQLType, GraphQLObjectType):
|
class GrapheneObjectType(GrapheneGraphQLType, GraphQLObjectType):
|
||||||
|
pass
|
||||||
def __init__(self, *args, **kwargs):
|
|
||||||
super(GrapheneObjectType, self).__init__(*args, **kwargs)
|
|
||||||
self.check_interfaces()
|
|
||||||
|
|
||||||
def check_interfaces(self):
|
|
||||||
if not self._provided_interfaces:
|
|
||||||
return
|
|
||||||
for interface in self._provided_interfaces:
|
|
||||||
if isinstance(interface, GrapheneInterfaceType):
|
|
||||||
interface.graphene_type.implements(self.graphene_type)
|
|
||||||
|
|
||||||
|
|
||||||
class GrapheneScalarType(GrapheneGraphQLType, GraphQLScalarType):
|
class GrapheneScalarType(GrapheneGraphQLType, GraphQLScalarType):
|
||||||
|
|
|
@ -26,11 +26,13 @@ class NodeMeta(ObjectTypeMeta):
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def _create_objecttype(cls, name, bases, attrs):
|
def _create_objecttype(cls, name, bases, attrs):
|
||||||
# The interface provided by node_definitions is not an instance
|
|
||||||
# of GrapheneInterfaceType, so it will have no graphql_type,
|
|
||||||
# so will not trigger Node.implements
|
|
||||||
cls = super(NodeMeta, cls)._create_objecttype(cls, name, bases, attrs)
|
cls = super(NodeMeta, cls)._create_objecttype(cls, name, bases, attrs)
|
||||||
cls.implements(cls)
|
require_get_node = Node._meta.graphql_type in cls._meta.graphql_type._provided_interfaces
|
||||||
|
if require_get_node:
|
||||||
|
assert hasattr(
|
||||||
|
cls, 'get_node'), '{}.get_node method is required by the Node interface.'.format(
|
||||||
|
cls.__name__)
|
||||||
|
|
||||||
return cls
|
return cls
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
|
@ -64,25 +66,14 @@ class NodeMeta(ObjectTypeMeta):
|
||||||
class Node(six.with_metaclass(NodeMeta, Interface)):
|
class Node(six.with_metaclass(NodeMeta, Interface)):
|
||||||
_connection = None
|
_connection = None
|
||||||
resolve_type = None
|
resolve_type = None
|
||||||
use_global_id = True
|
|
||||||
|
|
||||||
@classmethod
|
|
||||||
def require_get_node(cls):
|
|
||||||
return Node._meta.graphql_type in cls._meta.graphql_type._provided_interfaces
|
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def from_global_id(cls, global_id):
|
def from_global_id(cls, global_id):
|
||||||
return from_global_id(global_id)
|
return from_global_id(global_id)
|
||||||
# if cls is Node:
|
|
||||||
# return from_global_id(global_id)
|
|
||||||
# raise NotImplementedError("You need to implement {}.from_global_id".format(cls.__name__))
|
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def to_global_id(cls, type, id):
|
def to_global_id(cls, type, id):
|
||||||
return to_global_id(type, id)
|
return to_global_id(type, id)
|
||||||
# if cls is Node:
|
|
||||||
# return to_global_id(type, id)
|
|
||||||
# raise NotImplementedError("You need to implement {}.to_global_id".format(cls.__name__))
|
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def resolve_id(cls, root, args, context, info):
|
def resolve_id(cls, root, args, context, info):
|
||||||
|
@ -111,16 +102,3 @@ class Node(six.with_metaclass(NodeMeta, Interface)):
|
||||||
node = cls
|
node = cls
|
||||||
cls._connection = type('{}Connection'.format(cls.__name__), (Connection,), {'Meta': Meta})
|
cls._connection = type('{}Connection'.format(cls.__name__), (Connection,), {'Meta': Meta})
|
||||||
return cls._connection
|
return cls._connection
|
||||||
|
|
||||||
@classmethod
|
|
||||||
def implements(cls, object_type):
|
|
||||||
'''
|
|
||||||
We check here that the object_type have the required get_node method
|
|
||||||
in it
|
|
||||||
'''
|
|
||||||
if cls.require_get_node():
|
|
||||||
assert hasattr(
|
|
||||||
object_type, 'get_node'), '{}.get_node method is required by the Node interface.'.format(
|
|
||||||
object_type.__name__)
|
|
||||||
|
|
||||||
return super(Node, cls).implements(object_type)
|
|
||||||
|
|
|
@ -178,11 +178,3 @@ class Interface(six.with_metaclass(ObjectTypeMeta)):
|
||||||
if not isinstance(self, ObjectType):
|
if not isinstance(self, ObjectType):
|
||||||
raise Exception("An interface cannot be intitialized")
|
raise Exception("An interface cannot be intitialized")
|
||||||
super(Interface, self).__init__(*args, **kwargs)
|
super(Interface, self).__init__(*args, **kwargs)
|
||||||
|
|
||||||
@classmethod
|
|
||||||
def implements(cls, object_type):
|
|
||||||
'''
|
|
||||||
We use this function for customizing when a ObjectType have this class as Interface
|
|
||||||
For example, if we want to check that the ObjectType have some required things
|
|
||||||
in it like Node.get_node
|
|
||||||
'''
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user