Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: Back-port compatibility fixes for wp-graphql-content-blocks to SnapWP Helper plugin #28

Merged
merged 2 commits into from
Nov 6, 2024

Conversation

Ta5r
Copy link
Contributor

@Ta5r Ta5r commented Nov 5, 2024

What

In this PR, I backported specific compatibility fixes from wp-graphql-content-blocks to snapwp-helper to resolve issues noted in issue #224. The main updates include adjustments to the ContentBlocksResolver.php and the SchemaFilters.php file.

Why

This change is necessary because snapwp-helper was getting incompatible with WPGraphQL Content Blocks 4.2.0. This incompatibility was causing issues. Backporting these changes allows snapwp-helper to remain compatible with WPGraphQL Content Blocks plugin.

Related Issue(s):

Closes https://github.com/rtCamp/headless/issues/231

How

  1. Reviewed Fixes: I focused on the relevant code sections in snapwp-helper#25 and wp-graphql-content-blocks#31, specifically examining:
  • src/Modules/GraphQL/Data/ContentBlocksResolver.php
  • src/Modules/GraphQL/SchemaFilter.php
  1. Backported Compatibility Changes: I back ported over the necessary code from wp-graphql-content-blocks into snapwp-helper.

Testing Instructions

  1. Open GraphiQL IDE.
  2. Enter the following query:
query GetCurrentTemplate($uri: String!) {
  templateByUri(uri: $uri) {
    editorBlocks {
      name
      ... on CoreQueryNoResults{
        renderedHtml
      }
    }
  }
}
  1. Expect the following response (pfa screenshot)

Screenshots

Screenshot 2024-11-06 at 11 21 48 AM

Checklist

  • I have read the Contribution Guidelines.
  • My code is tested to the best of my abilities.
  • My code passes all lints (PHPCS, PHPStan, ESLint, etc).
  • My code has detailed inline documentation.
  • I have added unit tests to verify the code works as intended.
  • I have updated the project documentation accordingly.

@Ta5r Ta5r requested a review from justlevine November 5, 2024 10:22
@Ta5r
Copy link
Contributor Author

Ta5r commented Nov 5, 2024

Desired results of query in GraphiQL IDE :
Screenshot 2024-11-05 at 3 52 49 PM
(debug mode on)
Screenshot 2024-11-05 at 3 53 27 PM

Results from my work :
Screenshot 2024-11-05 at 3 54 08 PM
(debug mode on)
Screenshot 2024-11-05 at 3 54 34 PM

Copy link
Collaborator

@justlevine justlevine left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall the backport looks good.

Fix the comments, fill out the PR description and this should be ready.

@@ -37,11 +37,11 @@ final class SchemaFilters implements Registrable {
*/
public function register_hooks(): void {
// No need to check for dependencies, since missing filters will just be ignored.
add_filter( 'wpgraphql_content_blocks_handle_do_block', [ ContentBlocksResolver::class, 'handle_do_block' ], 10, 1 );
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is why we're not getting the inner blocks - you got rid of the graphql_object_fields filter which let us overload the entire class, and instead are only overloading the internal handle_do_block().

Revert this and your PR should be working.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Donew ✅

@@ -27,6 +27,20 @@ final class ContentBlocksResolver {
public static function resolve_content_blocks( $node, $args, $allowed_block_names = [] ): array {
global $post_id;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove this it's unused and removed in v4.2.0

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed 🚀

@Ta5r
Copy link
Contributor Author

Ta5r commented Nov 6, 2024

Desired response :

Screenshot 2024-11-06 at 11 20 35 AM

Response achieved ✅ :

Screenshot 2024-11-06 at 11 21 48 AM

The error section for both the responses for the following given query are same with the following debugMesasge and the data section are also showing same and complete desired results ✅ .

Query:

query GetCurrentTemplate($uri: String!) {
  templateByUri(uri: $uri) {
    editorBlocks {
      name
      ... on CoreQueryNoResults{
        renderedHtml
      }
    }
  }
}

Response:

"debugMessage": "Attempt to assign property \"parsed_block\" on null",

🚀 🚀 🚀

@Ta5r Ta5r changed the title dev : backport changes from CBR from block-model-david and SchemaFilt… Fix: Back-port compatibility fixes for wp-graphql-content-blocks to SnapWP Helper plugin Nov 6, 2024
@Ta5r Ta5r marked this pull request as ready for review November 6, 2024 06:44
@justlevine justlevine merged commit 95ceb4d into develop Nov 6, 2024
8 checks passed
@justlevine justlevine deleted the fix/model-compat branch November 6, 2024 11:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants