torchbox / wagtail-grapple

A Wagtail app that makes building GraphQL endpoints a breeze!

Home Page:https://wagtail-grapple.readthedocs.io/en/latest/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Document `CustomQuery` example for `register_schema_query` hook

Morsey187 opened this issue · comments

I'm on a project where we've found ourselves having to use a custom query via the register_schema_query hook for a snippet model, we're no longer querying via snippets because of this and I've had to resolve a RichtextField myself, for example:

class AlertObjectType(graphene.ObjectType):
    title = graphene.String(required=True)
    richtext = graphene.String(required=True)

    def resolve_message(self, info, **kwargs):
        if grapple_settings.RICHTEXT_FORMAT == "html":
            return render_to_string(
                "wagtailcore/richtext.html",
                {"html": expand_db_html(self.richtext)},
            )
        return self.richtext

We could either document an example of a CustomQuery class with a wagtail field on this page to hightlight this issue, or create a fix and document a cleaner solution.

Improving docs is a always a good thing.

Alternatively, we could perhaps create a new GraphQLRichText model that does all of this for devs?

I'd be in favour of adding a new GraphQLRichText field type. I'm on holiday for 2 weeks now but definitely keen to pick this one up myself if no one gets to it before then.