pristas-peter / wp-graphql-gutenberg

Query gutenberg blocks with wp-graphql
https://wp-graphql-gutenberg.netlify.app
GNU General Public License v3.0
299 stars 62 forks source link

blocksJSON error with WordPress 6.5 #204

Open colis opened 5 months ago

colis commented 5 months ago

There seems to be a validation issue with the blocksJSON field and WordPress 6.5.

This is what I'm seeing

[
  {
    "message": "Internal server error",
    "locations": [
      {
        "line": 113,
        "column": 3
      }
    ],
    "path": [
      "lot",
      "blocksJSON"
    ],
    "extensions": {
      "category": "internal"
    },
    "debugMessage": "'type' keyword contains unknown value: rich-text"
  }
]

Due to this error the blocksJSON field returns null. Reverting to WP 6.4 solves the problem.

This is the check that fails:

https://github.com/pristas-peter/wp-graphql-gutenberg/blob/bacabca662698871ecc8b297c7af3b5b95d431c1/vendor/opis/json-schema/src/Validator.php#L554-L561

https://github.com/pristas-peter/wp-graphql-gutenberg/blob/bacabca662698871ecc8b297c7af3b5b95d431c1/vendor/opis/json-schema/src/IValidatorHelper.php#L23

Steps to reproduce:

  1. Update WordPress to version 6.5
  2. Go to the WP GraphQL Gutenberg plugin settings page and click the “Update” button to update the block registry
  3. Go to the GraphiQL IDE and execute a query that contains the blocksJSON field
colis commented 5 months ago

It looks like the only way to pass the schema validation is to add the rich-text type to the ValidatorHelper JSON_TYPES array, e.g.

<?php

namespace WPGraphQLGutenberg\Schema;

use Opis\JsonSchema\ValidatorHelper;

class CustomValidatorHelper extends ValidatorHelper
{
    const JSON_TYPES = ["null", "boolean", "number", "integer", "string", "array", "object", "rich-text"];
}

and then use the new CustomValidatorHelper class when instantiating the Validator

$validator = new Validator( new CustomValidatorHelper() );

instead of https://github.com/pristas-peter/wp-graphql-gutenberg/blob/bacabca662698871ecc8b297c7af3b5b95d431c1/src/Blocks/Block.php#L158

noonstudio commented 5 months ago

Related to the 6.5 Wordpress Update – to this have you noticed that the 'content' attribute on is now no longer valid on the Core Block attributes. If so have you managed to overcome this?

 ... on CoreParagraphBlock {
        attributes {
          ... on CoreParagraphBlockAttributes {
            align
            anchor
            className
            content
          }
        }
      }
colis commented 5 months ago

@noonstudio you also need to change a couple other files

  1. https://github.com/pristas-peter/wp-graphql-gutenberg/blob/bacabca662698871ecc8b297c7af3b5b95d431c1/src/Schema/Types/BlockTypes.php#L45

needs to be

case 'rich-text':
case 'string':
    $type = 'String';
    break;
  1. https://github.com/pristas-peter/wp-graphql-gutenberg/blob/bacabca662698871ecc8b297c7af3b5b95d431c1/src/Blocks/Block.php#L60

needs to be

case 'html':
case 'rich-text':
fantaz-st commented 5 months ago

Related to the 6.5 Wordpress Update – to this have you noticed that the 'content' attribute on is now no longer valid on the Core Block attributes. If so have you managed to overcome this?

 ... on CoreParagraphBlock {
        attributes {
          ... on CoreParagraphBlockAttributes {
            align
            anchor
            className
            content
          }
        }
      }

yes, just realized that.