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

Add the block data api plugin #77

Merged
merged 10 commits into from
Feb 8, 2024
Merged

Conversation

ingeniumed
Copy link
Contributor

@ingeniumed ingeniumed commented Jan 9, 2024

Description

The purpose of this PR is to add the block data api plugin into the bundle. Since the block data api plugin has a rest and graphQL endpoint, this will now enable both of the APIs with this bundle.

The eventual goal would be to replace the bespoke the WPGraphQL Content blocks plugin, in favour of this plugin. The first step is add the plugin in, and then slowly add in any missing features so we can eventually deprecate it.

To review this PR, the changes that have been made:

  • Added the plugin using git subtree:

git remote add -f block-data-api-remote git@github.com:Automattic/vip-block-data-api.git
git subtree add --prefix lib/vip-block-data-api block-data-api-remote trunk --squash

The following is how you update it:

git fetch block-data-api-remote trunk
git subtree pull --prefix lib/vip-block-data-api block-data-api-remote trunk --squash

  • Added the block data api as a setting that can be turned on and off within the settings.php
  • Required the plugin if its enabled within the vip-decoupled.php
  • Updated the README with this new plugin with potential deprecation plans.

Steps to Test

  • Load up the dev-env or wp-env and enable this plugin
  • Ensure the graphQL endpoint can be hit, using the query:
query AllPosts {
  posts {
    nodes {
      id
      title
      contentBlocks {
        blocks {
          attributes {
            name
            value
          }
          name
          innerHTML
        }
        isGutenberg
        version
      }
    }
  }
}
  • Ensure the wp-json/vip-block-data-api/v1/posts/1/blocks rest endpoint can be hit

@ingeniumed ingeniumed requested a review from a team as a code owner January 9, 2024 03:58
@ingeniumed ingeniumed self-assigned this Jan 9, 2024
@alecgeatches
Copy link
Contributor

alecgeatches commented Jan 9, 2024

Tested this locally, works great! Used this query to test the Block data WPGraphQL integration as well:

query AllPosts {
  posts {
    nodes {
      id
      title
      blocksData {
        blocks {
          name
          attributes {
            name
            value
          }
        }
      }
    }
  }
}

After setting permalinks, the REST API at wp-json/vip-block-data-api/v1/posts/1/blocks worked properly too. Looks good to me!

/**
* VIP Block Data API.
*/
if ( is_plugin_enabled( 'block-data-api' ) ) {
Copy link
Member

Choose a reason for hiding this comment

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

Is there a chance the Block Data API also lands in mu-plugins? If so, and you want to prefer the mu-plugins version, you might want to proactively add some logic here to determine which version "wins."

Copy link
Contributor

Choose a reason for hiding this comment

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

Good question! We have that logic built-in. In the plugin itself we verify that we're not double-loading. On the mu-plugins integration side, we also have logic to prefer the customer version of the plugin, if installed.

I spent some time just now testing what happens if the Block Data API plugin is installed, as well as the bundle with the Block Data API feature enabled, as well as the mu-plugins version. The priority goes:

  1. Plugin version first
  2. Bundle version second, if the plugin is disabled (second alphabetically)
  3. The mu-plugins version of the plugin, if everything else is disabled

This fits our original intent to prefer customer code first, and works fine between the bundle and normal Block Data API plugin as well. Everything is working as designed.

README.md Outdated
### WPGraphQL Preview

This plugin overrides WordPress's native preview functionality and securely sends you to your decoupled frontend to preview your content. This ensures that your preview content has parity with your published content. It works by issuing a one-time use token, locked to a specific post, that can be redeemed by the frontend to obtain preview content for that post.

**This plugin currently only works with our Next.js boilerplate** and should be disabled if you are not using it. If you are interested in using this plugin for other frontend frameworks, please see the [preview `README`][preview-readme].

### VIP Block Data API
Copy link
Member

Choose a reason for hiding this comment

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

You might want to put both options next to each other and add a "Which should I choose?" section. That section can even just say, "we already recommend the block data API but here are some caveats"

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Great point, thanks for pointing that out. I've added this, and added what I think would be helpful in making this decision. Lemme know what you think.

ingeniumed and others added 3 commits January 12, 2024 14:55
0c0d679 Merge pull request #56 from Automattic/planned-release/1.2.0
b8d47ef Merge pull request #54 from Automattic/update/warning-for-php-8-and-abover
6d57703 Version the right way
6de847a Set the config for the php v to 8.0 as well
b3f4479 Require php 8, and set the symfony versions
fc85182 php configs set to 8.0
11407ea set min wp to 5.9
91ba9b1 Set min version to 8.0, upgrade packages and fix include/exclude bug

git-subtree-dir: lib/vip-block-data-api
git-subtree-split: 0c0d679b27d41afd3bed20758de4aed3d75f2cd6
@alecgeatches
Copy link
Contributor

Note here - we just merged a change into the Block Data API and released version 1.2.0. I've merged those changes into this PR.

Copy link
Contributor

@alecgeatches alecgeatches left a comment

Choose a reason for hiding this comment

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

Approving for the merge. Thank you @ingeniumed for the integration and documentation!

@alecgeatches alecgeatches merged commit f85b99e into trunk Feb 8, 2024
2 checks passed
@alecgeatches alecgeatches deleted the add/block-data-api-to-bundle branch February 8, 2024 19:54
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.

3 participants