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

Block registry missing error does not appear in GraphQL response #123

Open kellenmace opened 3 years ago

kellenmace commented 3 years ago

When the plugin is installed on a new WordPress site and the developer attempts to make a GraphQL request before generating the blocks registry for the first time, the following exception is thrown in PHP:

WPGraphQLGutenberg\Blocks\RegistryNotSourcedException: Client side block registry is missing. You need to open up gutenberg or load it from WPGraphQLGutenberg Admin page.

None of that wording comes through in the GraphQL response, though. All the developer sees is this, even with WPGraphQL Debug Mode enabled:

{
  "code": "internal_server_error",
  "message": "<p>There has been a critical error on this website.</p><p><a href=\"https://wordpress.org/support/article/faq-troubleshooting/\">Learn more about troubleshooting WordPress.</a></p>",
  "data": {
    "status": 500
  },
  "additional_errors": []
}

Ideally, this wording would be included in the response so the developer knows what the problem is.

Using this instead may fix the issue:

throw new GraphQL\Error\UserError(
    __(
        'Client-side block registry is missing. You need to open up Gutenberg or load it from the WPGraphQL Gutenberg Admin page.',
        'wp-graphql-gutenberg'
    )
);
pristas-peter commented 3 years ago

👍 Feel free to create PR for that and it will be merged

kellenmace commented 2 years ago

I tried to swap this out with GraphQL\Error\UserError like in my example above, but it still does not result in the error message being returned in the response. Maybe that needs to happen at a different hook or something - I'm not sure.