From a0416f4d49d3bc8e23e51c74295e2dd6f5f03b55 Mon Sep 17 00:00:00 2001 From: Jan Baykara Date: Wed, 29 Jul 2020 09:33:23 +0000 Subject: [PATCH] Add support for custom interfaces Allow usage like: ``` class Event(HeadlessPreviewMixin, Page): @classmethod def get_interface(self, interface): class EventInterface(graphene.Interface): saved = graphene.Boolean(argument_1=graphene.Boolean(required=True), required=True) def resolve_saved(self, info, **kwargs): print("resolve_saved", info.context.user) return False return (interface, EventInterface, ) ``` --- grapple/actions.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/grapple/actions.py b/grapple/actions.py index 41dd06ab..e5f84178 100644 --- a/grapple/actions.py +++ b/grapple/actions.py @@ -212,7 +212,7 @@ class StubMeta: "lazy": True, "name": type_name, "base_type": base_type, - "interface": interface, + "interface": cls.get_interface(interface) if hasattr(cls, 'get_interface') else interface, }, } @@ -235,7 +235,7 @@ def load_type_fields(): # Recreate the graphene type with the fields set class Meta: model = cls - interfaces = (interface,) if interface is not None else tuple() + interfaces = interface if type(interface) is tuple else (interface, ) if interface is not None else tuple() type_meta = {"Meta": Meta, "id": graphene.ID(), "name": type_name} exclude_fields = get_fields_and_properties(cls)