diff --git a/graphene/generators/definitions.py b/graphene/generators/definitions.py index 68251acb..42f08f52 100644 --- a/graphene/generators/definitions.py +++ b/graphene/generators/definitions.py @@ -19,17 +19,7 @@ class GrapheneInterfaceType(GrapheneGraphQLType, GraphQLInterfaceType): class GrapheneObjectType(GrapheneGraphQLType, GraphQLObjectType): - - 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) + pass class GrapheneScalarType(GrapheneGraphQLType, GraphQLScalarType): diff --git a/graphene/relay/node.py b/graphene/relay/node.py index fbccfd4b..793cd738 100644 --- a/graphene/relay/node.py +++ b/graphene/relay/node.py @@ -26,11 +26,13 @@ class NodeMeta(ObjectTypeMeta): @staticmethod 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.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 @staticmethod @@ -64,25 +66,14 @@ class NodeMeta(ObjectTypeMeta): class Node(six.with_metaclass(NodeMeta, Interface)): _connection = 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 def from_global_id(cls, 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 def to_global_id(cls, 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 def resolve_id(cls, root, args, context, info): @@ -111,16 +102,3 @@ class Node(six.with_metaclass(NodeMeta, Interface)): node = cls cls._connection = type('{}Connection'.format(cls.__name__), (Connection,), {'Meta': Meta}) 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) diff --git a/graphene/types/objecttype.py b/graphene/types/objecttype.py index c2825b70..5c67d4b7 100644 --- a/graphene/types/objecttype.py +++ b/graphene/types/objecttype.py @@ -178,11 +178,3 @@ class Interface(six.with_metaclass(ObjectTypeMeta)): if not isinstance(self, ObjectType): raise Exception("An interface cannot be intitialized") 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 - '''