wpengine / wp-graphql-content-blocks

Plugin that extends WPGraphQL to support querying (Gutenberg) Blocks as data
https://faustjs.org/docs/gutenberg/wp-graphql-content-blocks
GNU General Public License v2.0
107 stars 14 forks source link

Missing fields in GraphQL query #225

Closed MKlblangenois closed 6 months ago

MKlblangenois commented 6 months ago

I recently upgrade WordPress core and plugins to the latest version, and now when I try to generate schemas, it gave me error about core blocks that missing some field (like text for CoreButton or caption for CoreImage) image

When I inspect the schema.graphql from the last release, these fields exist but when I try to query them on GraphiQL IDE, they doesn't exist. SCR-20240403-irnt

I've tried with default theme and other plugin disabled but the issue persist.

MKlblangenois commented 6 months ago

After several tests, it seems that the problem comes from the update to WordPress 6.5, I tested up to 6.4.3 without problem

theodesp commented 6 months ago

@MKlblangenois it looks like WordPress has indeed changed up their block fields with some breaking changes. At least GraphQL was able to detect any conflicts here before it's too late.

Hovever its quite tricky to roll out a new release of the @faust/blocks package since we will have to do a major upgrade release version to make this work. Clients could still be using old versions, and if we update the fragments now, it will break their code.

I could suggest to override the block fragments directly before you export them until we provide a new release.

Here is an example: https://github.com/wpengine/faustjs/blob/canary/examples/next/block-support/wp-blocks/index.js

import { CoreBlocks } from '@faustwp/blocks';
import BlockB from './block-b/Component.js';
import { gql } from '@apollo/client';

CoreBlocks.CoreParagraph.fragments.entry = gql`

` // Update Fragment query here before exporting component.

export default {
  CoreParagraph: CoreBlocks.CoreParagraph,
  ...
theodesp commented 6 months ago

I could also suggest to open ticket in https://github.com/wpengine/faustjs so that we are aware of this change.

colis commented 6 months ago

This is because the source for those fields has changed to rich-text.

Adding rich-text as a case in the following switch should solve the problem

https://github.com/wpengine/wp-graphql-content-blocks/blob/9b0a63e24c1a1173c65b37de5523570aec65d332/includes/Blocks/Block.php#L370

theodesp commented 6 months ago

Hey @colis How on earth did they add this type without even documenting it? Strange. I will provide a PR today.

theodesp commented 6 months ago

Hey @colis latest version fixes this issue.