wp-graphql-content-blocks icon indicating copy to clipboard operation
wp-graphql-content-blocks copied to clipboard

Latest version of Wordpress 6.5.4 returns null for various core block attributes

Open rudiwebworx opened this issue 1 year ago • 7 comments

On the latest version of wordpress 6.5.4 getting the following errors

 graphQLErrors: [
    {
      message: 'Cannot query field "tagName" on type "CoreButtonAttributes".',
      extensions: [Object],
      locations: [Array]
    },
    {
      message: 'Cannot query field "type" on type "CoreButtonAttributes". Did you mean "style"?',
      extensions: [Object],
      locations: [Array]
    },
    {
      message: 'Fields "attributes" conflict because subfields "align" conflict because they return conflicting types String and String!. Use different aliases on the fields to fetch both if this was intentional.',
      extensions: [Object],
      locations: [Array]
    },

Seems that there have been some changes to gutenberg core blocks that require the refactoring of this plugin.

rudiwebworx avatar Jun 06 '24 10:06 rudiwebworx

Hello @rudiwebworx are you using the latest version of this plugin? I have a similar setup but I cannot reproduce this issue.

theodesp avatar Jun 13 '24 12:06 theodesp

Hi 👋 — We're also running into this upon updating from WordPress 6.4.3 to WordPress 6.5.5:

Screen Shot 2024-07-09 at 2 59 16 PM Screen Shot 2024-07-09 at 2 55 32 PM

This broke all pages where these fields were queried and forced us to roll back and defer updates.

Our environment, arrows indicating the updated environment we tried that resulted in an outage:

Plugin Version
Faust 1.3.0 → 1.3.2
WordPress 6.4.3 → 6.5.5
WPGraphQL 1.26.0 → 1.27.2

Essential fields like content and caption are now suddenly missing from Gutenberg queries, with no visible alternates in the IDE. I'm not sure if this an issue arising from WordPress Gutenberg's end or not.

I tried updating plugins and the system first—no-go. Then tried just updating the system—also a no-go. That's why I suspected the issue being that Gutenberg blocks have changed but that change isn't reflected in the content block plugin for GraphQL.

lindseybradford avatar Jul 09 '24 21:07 lindseybradford

@theodesp yes we are using the latest with the following:

  • WPGraphQL Content Blocks: Version 4.0.1
  • WPGraphQL: Version 1.27.2
  • Faust.js™: Version 1.3.2
  • Wordpress: 6.5.5

Errors: Error occurred prerendering page "/en". Read more: https://nextjs.org/docs/messages/prerender-error ApolloError: Fields "attributes" conflict because subfields "align" conflict because they return conflicting types String and String!. Use different aliases on the fields to fetch both if this was intentional. Fields "attributes" conflict because subfields "align" conflict because they return conflicting types String and String!. Use different aliases on the fields to fetch both if this was intentional.....

In GraphQL IDE query e.g

query PostBySlug {
  pages(where: {id: 2}) {
    nodes {
      editorBlocks {
        ... on CoreParagraph {
          anchor
          apiVersion
          attributes {
            content
            align
          }
        }
        ... on CoreButtons {
          anchor
          apiVersion
          attributes {
            align
            cssClassName
            className
            style
          }
        }
        ... on CoreButton {
          anchor
          apiVersion
          attributes {
            title
            type
            url
          }
        }
      }
      title
      slug
    }
  }
}

returns null several times for align... e.g

{
  "anchor": null,
  "apiVersion": 3,
  "attributes": {
    "content": "Beast Philanthropy is a 501(c)3 organization ....",
    "align": null
  }
},

Rolling back to WP 6.4.5 fixes this so assuming gutenberg has changed something which means this plugin needs some refactoring. Thanks in advance!

rudiwebworx avatar Jul 10 '24 11:07 rudiwebworx

Hey! I run with the same issue on my side with an ACF block when I try to get attributes.align

image

BlockCtaSmall.fragments = {
	blocks: gql`
		fragment BlockCtaFragment on EditorBlock {
			... on AcfBlockCta {
				anchor
				fields: blockCta {
					title
					description
					button {
						url
						title
						target
					}
				}
			}
		}
	`,
};
Plugin Version
WordPress 6.6
WPGraphQL 1.27.0
WPGraphQL Content Blocks 4.0.1

MKlblangenois avatar Jul 19 '24 06:07 MKlblangenois

Hey! I run with the same issue on my side with an ACF block when I try to get attributes.align

image

BlockCtaSmall.fragments = {
	blocks: gql`
		fragment BlockCtaFragment on EditorBlock {
			... on AcfBlockCta {
				anchor
				fields: blockCta {
					title
					description
					button {
						url
						title
						target
					}
				}
			}
		}
	`,
};

Plugin Version WordPress 6.6 WPGraphQL 1.27.0 WPGraphQL Content Blocks 4.0.1

I think this is a separate issue, that I've been meaning to file too – but it's unclear to me whether the bug is in this repo or stemming from the graphql-acf plugin.

I'd wager a guess that you are querying 'align' on all blocks, and the error is thrown only on the acf block. to fix this, you need to remove 'align' from the part that queries all blocks and add it back to each individual fragment. for acf blocks, you then need to query align as an alias, like so

  attributes {
    backgroundColor
    alignment: align
  }

finally you can rename 'alignment' back to 'align' in the endpoint that pulls the data.

not pretty but it works.

erikhartin avatar Jul 21 '24 07:07 erikhartin

I ran into this as well. I believe this is an issue related to a change in WordPress core that is getting passed downstream.

WPGraphQL Content Blocks reads the block registry and converts it into a GraphQL Schema. If a registration of a block is changed, it can lead to changes in the Schema, and I believe that is the case here.

I want to look into it further, but I do believe it's related to a WordPress core update.

jasonbahl avatar Aug 06 '24 15:08 jasonbahl

Upon review -

  1. Using WP 6.6, PHP 8.2, and WPGraphQL Content Blocks 4.2.0, all of the "missing fields" mentioned in this ticket are visible:

    • CoreButtonAttributes.tagName image
    • CoreButtonAttributes.type: image
    • CoreHeadingAttributes.content: image
    • CoreQuoteAttributes.citation: image
    • CorePreformattedAttributes.content: image
    • CoreImageAttributes.caption: image
  2. The remaining issue is that this plugin generates types optimistically instead of deterministically, as Jason mentioned, which can be worked around by aliasing. This causes type conflicts, potential changes between versions, and non-DX friendly types (e.g. using float for integer values or strings instead of enums).

Using determinate attribute types would both fix the type conflicts along with the possibility of an attribute getting removed/renamed from the block.json (which didnt happen btw).

This is being tangentially tracked in #136 (see this outdated list of type issues: https://github.com/wpengine/wp-graphql-content-blocks/issues/136#issuecomment-1685250158 )

justlevine avatar Sep 21 '24 23:09 justlevine

Currently I cannot replicate the bug in WordPress 6.5.5 with different variations of the FaustWP, WPGraphQL and WPGraphQL Content Blocks installed or with WordPress 6.7.1 either.

colinmurphy avatar Dec 13 '24 15:12 colinmurphy

For reference here is the query I used for testing

query PostBySlug {
  pages(where: {id: 2}) {
    nodes {
      editorBlocks {
        ... on CoreParagraph {
          anchor
          apiVersion
          attributes {
            content
            align
          }
        }
      }
      title
      slug
    }
  }
}

Screenshot

image

colinmurphy avatar Dec 13 '24 16:12 colinmurphy

Please feel free to re-open this ticket if you have any further issues. However we recommend that you update to the latest version of WPGraphQL Content Blocks (currently version 4.3.2).

Thank you for opening the ticket.

colinmurphy avatar Dec 13 '24 17:12 colinmurphy