diff --git a/grapple/actions.py b/grapple/actions.py index 96957ff1..899d8852 100644 --- a/grapple/actions.py +++ b/grapple/actions.py @@ -9,6 +9,7 @@ from django.apps import apps from django.core.exceptions import FieldDoesNotExist from django.db import models +from django.utils.module_loading import import_string from graphene_django.types import DjangoObjectType from wagtail.blocks import StructValue, stream_block from wagtail.contrib.settings.models import BaseGenericSetting, BaseSiteSetting @@ -268,7 +269,13 @@ class StubMeta: model = stub_model # Gather any interfaces, and discard None values - interfaces = {interface, *getattr(cls, "graphql_interfaces", ())} + interface_classes = list(getattr(cls, "graphql_interfaces", ())) + for i, interface_class in enumerate(interface_classes): + if isinstance(interface_class, str): + interface_classes[i] = import_string(interface_class) + interface_classes = tuple(interface_classes) + + interfaces = {interface, *interface_classes} interfaces.discard(None) type_meta = { diff --git a/tests/test_interfaces.py b/tests/test_interfaces.py index a1276010..58a83f55 100644 --- a/tests/test_interfaces.py +++ b/tests/test_interfaces.py @@ -89,21 +89,29 @@ def test_schema_for_page_with_graphql_interface(self): results = self.introspect_schema_by_type("AuthorPage") self.assertListEqual( sorted(results["data"]["__type"]["interfaces"], key=lambda x: x["name"]), - [{"name": "AdditionalInterface"}, {"name": "PageInterface"}], + [ + {"name": "AdditionalInterface"}, + {"name": "AlternativeInterface"}, + {"name": "PageInterface"}, + ], ) def test_schema_for_snippet_with_graphql_interface(self): results = self.introspect_schema_by_type("Advert") self.assertListEqual( sorted(results["data"]["__type"]["interfaces"], key=lambda x: x["name"]), - [{"name": "AdditionalInterface"}, {"name": "SnippetInterface"}], + [ + {"name": "AdditionalInterface"}, + {"name": "AlternativeInterface"}, + {"name": "SnippetInterface"}, + ], ) def test_schema_for_django_model_with_graphql_interfaces(self): results = self.introspect_schema_by_type("SimpleModel") self.assertListEqual( sorted(results["data"]["__type"]["interfaces"], key=lambda x: x["name"]), - [{"name": "AdditionalInterface"}], + [{"name": "AdditionalInterface"}, {"name": "AlternativeInterface"}], ) diff --git a/tests/testapp/interfaces.py b/tests/testapp/interfaces.py index 41baec05..dc11c314 100644 --- a/tests/testapp/interfaces.py +++ b/tests/testapp/interfaces.py @@ -7,6 +7,10 @@ class AdditionalInterface(graphene.Interface): additional_text = graphene.String() +class AlternativeInterface(graphene.Interface): + alternative_text = graphene.String() + + class CustomPageInterface(PageInterface): custom_text = graphene.String() diff --git a/tests/testapp/models/core.py b/tests/testapp/models/core.py index 732b1554..37a1dcaf 100644 --- a/tests/testapp/models/core.py +++ b/tests/testapp/models/core.py @@ -50,7 +50,10 @@ @register_singular_query_field("simpleModel") class SimpleModel(models.Model): - graphql_interfaces = (AdditionalInterface,) + graphql_interfaces = ( + AdditionalInterface, + "testapp.interfaces.AlternativeInterface", + ) def custom_middleware_one(next, root, info, **args): @@ -83,7 +86,10 @@ class AuthorPage(Page): content_panels = Page.content_panels + [FieldPanel("name")] graphql_fields = [GraphQLString("name")] - graphql_interfaces = (AdditionalInterface,) + graphql_interfaces = ( + AdditionalInterface, + "testapp.interfaces.AlternativeInterface", + ) class BlogPageTag(TaggedItemBase): @@ -264,7 +270,10 @@ class Advert(models.Model): GraphQLString("string_rich_text", source="rich_text"), GraphQLString("extra_rich_text", deprecation_reason="Use rich_text instead"), ] - graphql_interfaces = (AdditionalInterface,) + graphql_interfaces = ( + AdditionalInterface, + "testapp.interfaces.AlternativeInterface", + ) def __str__(self): return self.text