Skip to content

Block Data API throws error when there is no block content #92

@amanda-t

Description

@amanda-t

Describe the bug
When querying a post in GraphQL with no block content, even when using the Gutenberg editor, this block-data-api code causes an error to be thrown. It's ostensibly to check for classic editor content but will also throw an error when there is no block content (causing $has_blocks to return false and trigger the error). I would expect it to return an empty array for block content, not error out.

To Reproduce

  • Create a post with no blocks and query the post with:
query NewQuery {
  post(id: 1, idType: DATABASE_ID) {
    blocksDataV2 {
      blocks {
        name
        id
        parentId
        attributes {
          name
          value
        }
      }
    }
  }
}

Expected behavior
A data object for the post with blocks as an empty array should be returned:

"post": {
      "blocksDataV2": {
        "blocks": []
      }
    }

Actual behavior
Internal server error is returned, e.g.: vip-block-data-api-no-blocks - Error parsing post ID 1273: This post does not appear to contain block content. The VIP Block Data API is designed to parse Gutenberg blocks and can not read classic editor content. in /wp/wp-content/mu-plugins/vip-integrations/vip-block-data-api-1.4/src/analytics/analytics.php on line 58

Version of the plugin
1.4.5 (activated with \Automattic\VIP\Integrations\activate( 'block-data-api' ); in plugin-loader.php)

Additional context
We have a use case where custom post type pages are largely generated from external data sources, but it's possible to create pages for them in WordPress to allow for overrides of default options and/or add additional content with Gutenberg blocks. Many times users will only utilize custom meta fields with no need for actual blocks of content to be added to the Gutenberg editor.

Metadata

Metadata

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions