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

resolve_value missing from EmbedBlock #395

Open rachelhsmith opened 1 month ago

rachelhsmith commented 1 month ago

When using the value field of an EmbedBlock in a query, it errors with "Cannot return null for non-nullable field EmbedBlock.value."

Steps to reproduce:

  1. Define a StructBlock with an EmbedBlock field and register it with @register_streamfield_block
from wagtail.embeds import blocks as embeds_blocks

@register_streamfield_block
class EmbedStructBlock(blocks.StructBlock):
    embed = embeds_blocks.EmbedBlock()
  1. Register the field for GraphQL
from grapple.types import streamfield as grapple_streamfield

    graphql_fields = [
        grapple_streamfield.EmbedBlock(),
    ]
  1. Use this EmbedStructBlock in a StreamField of a Page model and execute a GraphQL query which requests ‘value’ on the embed field
… on EmbedStructBlock {
    testEmbed {
        value
    }
}

Switching the resolve_raw_value method of the EmbedBlock to resolve_value has solved this issue for me in the project I am currently working on

    def resolve_value(self, info, **kwargs):
        if isinstance(self, EmbedValue):
            return self
        return StreamFieldInterface.resolve_raw_value(info, **kwargs)

Should resolve_raw_value actually be resolve_value?