wp-graphql-gutenberg-acf icon indicating copy to clipboard operation
wp-graphql-gutenberg-acf copied to clipboard

Plugin breaks GraphQL Blocks API after upgrade to PHP 8

Open ole-treichel opened this issue 1 year ago • 5 comments

Hi,

My hosting provider just ugpraded to PHP 8 and now the GraphQL API for querying blocks is broken. I deactivated all plugins until I found that this plugin seems to be the culprit. All other plugins seem to work fine with PHP 8, with the exception of WP GraphQL Gutenberg 0.3.12. Keeping WP GraphWL Gutenberg at 0.3.11 seems to work fine.

If I query blocks with acf fields like this:

{
  posts {
    edges {
      node {
        title
        blocks {
          ... on MyAcfBlock {
            acf {
              headline
            }
          }
        }
      }
    }
  }
}

I get two errors (per Block in the response):

{
  "debugMessage": "get_object_vars(): Argument #1 ($object) must be of type object, array given",
  "message": "Internal server error",
  "extensions": {
    "category": "internal"
  },
  "locations": [
    {
      "line": 6,
      "column": 9
    }
  ],
  "path": [
    "posts",
    "edges",
    1,
    "node",
    "blocks"
  ]
},
{
  "debugMessage": "DOMDocument::loadHTML(): Argument #1 ($source) must not be empty",
  "message": "Internal server error",
  "extensions": {
    "category": "internal"
  },
  "locations": [
    {
      "line": 6,
      "column": 9
    }
  ],
  "path": [
    "posts",
    "edges",
    2,
    "node",
    "blocks"
  ]
},

And the blocks field returns null in the response.

Here a my other plugins versions:

  • WP GraphQL 1.12.2
  • WP GraphQL Gutenberg 0.3.11 (Tried 0.3.12, but this breaks GraphQL as well)
  • WP GraphQL for Advanced Custom Fields 0.6.1
  • Advanced Custom Fields Pro 6.0.4 (Tried 0.5.9 as well, still broken)

I am not a huge PHP expert. I looked through the code but could not find any direct reference to DOMDocument::loadHTML() or get_object_vars() so I guess this is in another dependency of this plugin?

If you could point me into the right direction I would be happy to try to fix the plugin for PHP 8 and make a PR.

Thanks in advance, and thanks for the plugin.

ole-treichel avatar Nov 15 '22 15:11 ole-treichel

Hey @ole-treichel, have you try the following resolve on issue pristas-peter/wp-graphql-gutenberg#162 ? I was in the same issue of you and updated these file has resolved the PHP error.

MKlblangenois avatar Nov 30 '22 09:11 MKlblangenois

Hi @MKlblangenois , sorry for the late response.

I figured this workaround out too. Thanks for pointing it out!

ACF Blocks still had problems on my side. The attributes where not parsed correctly (ACF Blocks returns the attributes as array, GraphQL expects them to be an object). If I convert the attributes to an object the validation passes and GraphQL works again, however the ACF fields are not actually resolved. All ACF related fields return null.

In the end I decided to ditch ACF Blocks and just use regular custom Gutenberg blocks for the site.

ole-treichel avatar Dec 14 '22 08:12 ole-treichel

Hi @ole-treichel, yes, I got this issue on my side too.

Downgrade ACF Pro to a version lower than 6 (5.12.4 on my case) has solve the issue, ACF 6 seems to have changed something but I haven't figured out what changed yet.

MKlblangenois avatar Dec 16 '22 07:12 MKlblangenois

From @jasonbahl -

ACF 6.0 and Using ACF Blocks in Gutenberg with GraphQL 1.13x will return null on the data. Right now we can only downgrade our ACF version to 5.12.x to resolve the null issue. Here is the comment from Jason:

WPGraphQL v1.13.0 introduced Connection and Edge Interfaces which enforce connections to connect to a Type that is a Node.

This updates the BlockEditorContentNode to implement the Node interface to play nicely with WPGraphQL v1.13+

NOTE: This PR also updates the code sniffer rules and fixes issues brought up by code sniffs

Reference: https://github.com/pristas-peter/wp-graphql-gutenberg/pull/165

NicholasRowe avatar Dec 16 '22 12:12 NicholasRowe

👋🏻 My recommendation would be to switch to use WPGraphQL Content Blocks (https://github.com/wpengine/wp-graphql-content-blocks) and the new WPGraphQL for ACF (https://github.com/wp-graphql/wpgraphql-acf)

With those 2 plugins, you can query Gutenberg Blocks (that have a block.json file, or you can add support for blocks that don't) and you can query for ACF Blocks and the ACF Field Groups associated with the blocks.

WPEngine is paying contributors to maintain WPGraphQL Content Blocks, and the ultimate goal is to get it to a state where it could be merged into core WPGraphQL.

Because WPGraphQL Content Blocks and WPGraphQL for ACF are supported by paid contributors, and this plugin was maintained by a community member that's since moved on to other work, I would recommend making the switch at your earliest convenience and helping contribute to any issues you run into over there.

jasonbahl avatar Dec 01 '23 17:12 jasonbahl