Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion grapple/actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -268,7 +269,12 @@ class StubMeta:
model = stub_model

# Gather any interfaces, and discard None values
interfaces = {interface, *getattr(cls, "graphql_interfaces", ())}
interface_classes = getattr(cls, "graphql_interfaces", ())
interface_classes = tuple(
import_string(i) if isinstance(i, str) else i for i in interface_classes
)

interfaces = {interface, *interface_classes}
interfaces.discard(None)

type_meta = {
Expand Down
7 changes: 7 additions & 0 deletions tests/test_interfaces.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,13 @@ def test_schema_for_django_model_with_graphql_interfaces(self):
[{"name": "AdditionalInterface"}],
)

def test_imports_graphql_interfaces_defined_by_str(self):
results = self.introspect_schema_by_type("SimpleModelWithAlternativeInterface")
self.assertListEqual(
sorted(results["data"]["__type"]["interfaces"], key=lambda x: x["name"]),
[{"name": "AdditionalInterface"}, {"name": "AlternativeInterface"}],
)


@tag("needs-custom-settings")
@skipUnless(
Expand Down
4 changes: 4 additions & 0 deletions tests/testapp/interfaces.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Generated by Django 5.0.14 on 2025-09-28 19:32

from django.db import migrations, models


class Migration(migrations.Migration):
dependencies = [
("testapp", "0002_create_homepage"),
]

operations = [
migrations.CreateModel(
name="SimpleModelWithAlternativeInterface",
fields=[
(
"id",
models.AutoField(
auto_created=True,
primary_key=True,
serialize=False,
verbose_name="ID",
),
),
],
),
]
8 changes: 8 additions & 0 deletions tests/testapp/models/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,14 @@ class SimpleModel(models.Model):
graphql_interfaces = (AdditionalInterface,)


@register_singular_query_field("simpleModelWithAlternativeInterface")
class SimpleModelWithAlternativeInterface(models.Model):
graphql_interfaces = (
AdditionalInterface,
"testapp.interfaces.AlternativeInterface",
)


def custom_middleware_one(next, root, info, **args):
info.context.custom_middleware_one = True
return next(root, info, **args)
Expand Down