torchbox / wagtail-grapple

A Wagtail app that makes building GraphQL endpoints a breeze!
https://wagtail-grapple.readthedocs.io/en/latest/
Other
151 stars 57 forks source link

On the current main branch, grapple fails to retreive the schema or perform any queries. #341

Closed chrisdevereux closed 12 months ago

chrisdevereux commented 1 year ago

Apologies if this is already known about - just thought I'd raise in case it isn't as I saw that a new version is due to be released soon. On the current main branch, grapple fails to retreive the schema or perform any queries.

These all return a graphql error: "Type Mutation must define one or more fields."

Can provide a more detailed reproduction if needed. It's a more or less fresh project with the following relevant package versions:

wagtail = "5.0.2"
wagtail-grapple = { git = "https://github.com/torchbox/wagtail-grapple.git", ref = "f75b8f76bd46e786ddeea1352d93daeec2628505" }
graphene = "3.2.2"

Adding the following to wagtail_hooks.py suppresses the issue:

@hooks.register("register_schema_mutation")
def register_author_mutation(mutation_mixins):
    '''
    Workaround for error where graphene fails with empty mutation type
    '''

    class DummyMutation(graphene.Mutation):
        class Arguments:
            value = graphene.String()

        ok = graphene.Boolean()

        def mutate(root, info, name, parent):
            return DummyMutation(ok=True)

    class Mutation(graphene.ObjectType):
        dummy = DummyMutation.Field()

    mutation_mixins.append(Mutation)
zerolab commented 1 year ago

oh! thank you for this, @chrisdevereux. I believe that comes from #336. Any chance you can test with ref="4e4d063fbfe0b99080cc7e95e34a9c4a6b9fb63c" ?

chrisdevereux commented 1 year ago

yep, that resolves it!

zerolab commented 12 months ago

The issue was in the fact we were registering the generic ObjectType as a mutation mixin

@hooks.register("register_schema_mutation")
def register_schema_mutation(mutation_mixins):
    mutation_mixins += [ObjectType]

ObjectType by itself doesn't define any fields..