diff --git a/graphene/relay/tests/test_node.py b/graphene/relay/tests/test_node.py index e5b4b961..943788e7 100644 --- a/graphene/relay/tests/test_node.py +++ b/graphene/relay/tests/test_node.py @@ -31,7 +31,7 @@ def test_node_no_get_node(): assert "MyNode.get_node method is required by the Node interface." == str(excinfo.value) -def test_node_no_get_node(): +def test_node_no_get_node_with_meta(): with pytest.raises(AssertionError) as excinfo: class MyNode(ObjectType): class Meta: diff --git a/graphene/types/definitions.py b/graphene/types/definitions.py index a5ce29f7..37b94604 100644 --- a/graphene/types/definitions.py +++ b/graphene/types/definitions.py @@ -162,7 +162,12 @@ class GrapheneObjectType(GrapheneFieldsType, GraphQLObjectType): self._interfaces = None # We clear the cached fields as could be inherited from interfaces self._field_map = None - self._provided_interfaces.append(get_graphql_type(interface)) + graphql_type = get_graphql_type(interface) + + if isinstance(graphql_type, GrapheneInterfaceType): + graphql_type.graphene_type.implements(self.graphene_type) + + self._provided_interfaces.append(graphql_type) class GrapheneInterfaceType(GrapheneFieldsType, GraphQLInterfaceType): diff --git a/graphene/types/interface.py b/graphene/types/interface.py index 3ebf90b2..daa0f072 100644 --- a/graphene/types/interface.py +++ b/graphene/types/interface.py @@ -40,9 +40,8 @@ class Interface(six.with_metaclass(InterfaceTypeMeta)): @classmethod def implements(cls, object_type): ''' - We use this function for customizing what the @implements function do - for each implementation. - For example, if we want to check that the class have some required things + 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 ''' - object_type._meta.graphql_type.add_interface(cls) + pass diff --git a/graphene/types/objecttype.py b/graphene/types/objecttype.py index afcba8f7..d48a7412 100644 --- a/graphene/types/objecttype.py +++ b/graphene/types/objecttype.py @@ -29,21 +29,16 @@ class ObjectTypeMeta(ClassTypeMeta): name=cls._meta.name or cls.__name__, description=cls._meta.description, fields=FieldMap(cls, bases=filter(None, inherited_types)), - interfaces=map(get_graphql_type, cls._meta.interfaces), + interfaces=[], ) + for interface in cls._meta.interfaces: + cls._meta.graphql_type.add_interface(interface) def implements(*interfaces): - from ..utils.get_graphql_type import get_graphql_type - def wrap_class(cls): for i in interfaces: - graphql_type = get_graphql_type(i) - if isinstance(graphql_type, GrapheneInterfaceType): - graphql_type.graphene_type.implements(cls) - else: - # We add the interface in the regular way - cls._meta.graphql_type.add_interface(graphql_type) + cls._meta.graphql_type.add_interface(i) return cls return wrap_class