diff --git a/docs/general-usage/interfaces.rst b/docs/general-usage/interfaces.rst index c27441bb..166fb0f8 100644 --- a/docs/general-usage/interfaces.rst +++ b/docs/general-usage/interfaces.rst @@ -115,7 +115,8 @@ in the interface: :: - snipeptType: String! + snippetType: String! + contentType: String! An example of querying all snippets: @@ -124,6 +125,7 @@ An example of querying all snippets: query { snippets { snippetType + contentType ...on Advert { id url diff --git a/grapple/types/interfaces.py b/grapple/types/interfaces.py index eaf85daa..5ebfc1d9 100644 --- a/grapple/types/interfaces.py +++ b/grapple/types/interfaces.py @@ -217,6 +217,7 @@ def get_snippet_interface(): class SnippetInterface(graphene.Interface): snippet_type = graphene.String(required=True) + content_type = graphene.String(required=True) @classmethod def resolve_type(cls, instance, info, **kwargs): @@ -224,3 +225,9 @@ def resolve_type(cls, instance, info, **kwargs): def resolve_snippet_type(self, info, **kwargs): return self.__class__.__name__ + + def resolve_content_type(self, info, **kwargs): + self.content_type = ContentType.objects.get_for_model(self) + return ( + f"{self.content_type.app_label}.{self.content_type.model_class().__name__}" + ) diff --git a/tests/test_grapple.py b/tests/test_grapple.py index 20df8bc3..c56d0f92 100644 --- a/tests/test_grapple.py +++ b/tests/test_grapple.py @@ -1592,6 +1592,7 @@ def test_snippets(self): { snippets { snippetType + contentType } } """ @@ -1604,3 +1605,4 @@ def test_snippets(self): snippets_data = executed["data"]["snippets"] self.assertEqual(snippets_data[0]["snippetType"], "Advert") + self.assertEqual(snippets_data[0]["contentType"], "testapp.Advert")