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
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
70 changes: 58 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,20 @@ This plugin bundle provides a number of plugins to help you quickly setup a deco
> ⚠️ This project is under active development. If you are a VIP customer, please let us know if you'd like to use this plugin and we can provide additional guidance. Issues and PRs are welcome. 💖

## Table of contents
- [Table of contents](#table-of-contents)
- [Installation](#installation)
- [Plugin activation](#plugin-activation)
- [Plugin activation](#plugin-activation)
- [Getting started](#getting-started)
- [Configuration](#configuration)
- [Setting the home URL](#setting-the-home-url)
- [Setting the home URL](#setting-the-home-url)
- [Jetpack Configuration](#jetpack-configuration)
- [Plugin settings](#plugin-settings)
- [Plugin settings](#plugin-settings)
- [Sub-plugins](#sub-plugins)
- [WPGraphQL](#wpgraphql)
- [WPGraphQL Content blocks](#wpgraphql-content-blocks)
- [WPGraphQL Preview](#wpgraphql-preview)
- [WPGraphQL](#wpgraphql)
- [WPGraphQL Preview](#wpgraphql-preview)
- [Block Data Plugins](#block-data-plugins)
- [WPGraphQL Content blocks](#wpgraphql-content-blocks)
- [VIP Block Data API](#vip-block-data-api)
- [Which Plugin Should I Choose?](#which-plugin-should-i-choose)
- [Contributing](#contributing)

## Installation
Expand All @@ -30,7 +32,7 @@ The latest version of the plugin can be downloaded from the [repository's Releas

### Plugin activation

For VIP sites, we recommend [activating plugins with code][wpvip-plugin-activate].
For VIP sites, we recommend [activating plugins with code][wpvip-plugin-activate].

For Non-VIP sites, activate the plugin in the WordPress Admin dashboard using the following steps:

Expand Down Expand Up @@ -94,7 +96,17 @@ This plugin bundle provides a number of "sub-plugins" that are commonly useful i

When updates are pushed out to WPGraphQL, we will update this plugin after evaluating it for compatibility and performance. If you need to run a different version of WPGraphQL, you can disable the bundled version and activate your own.

### WPGraphQL Content blocks
### 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].

### Block Data Plugins

There are 2 sub-plugins bundled for exposing the Gutenberg blocks - WPGraphQL Content Blocks and VIP Block Data API. In the near future, WPGraphQL Content Blocks will be deprecated in favour of just including the VIP Block Data API.

##### WPGraphQL Content blocks

This plugin exposes Gutenberg blocks as a field named `contentBlocks` on all post types that support a content editor:

Expand Down Expand Up @@ -125,11 +137,45 @@ This will allow you to easily map Gutenberg blocks to front-end components. Post

See our [Next.js boilerplate][nextjs-boilerplate] for an example of how to use and render these blocks.

### WPGraphQL Preview
##### VIP Block Data API

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 exposes Gutenberg blocks as JSON data, with integrations for both the official WordPress REST API and WPGraphQL. The GraphQL API exposes the blocks under a field name `blocksData` on all post types that support a content editor:

**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].
```graphQL
query GetPost {
post(id: "1", idType: DATABASE_ID) {
blocksData {
blocks {
id
name
attributes {
name
value
}
innerBlocks {
name
parentId
id
attributes {
name
value
}
}
}
}
}
}
```

Posts that do not support Gutenberg are not supported by this plugin. For more information, refer to the documentation [here](/~https://github.com/Automattic/vip-block-data-api).

#### Which Plugin Should I Choose?

We recommend the VIP Block Data API plugin, as the plugin of choice for exposing the Gutenberg blocks.

However, if you require exposing the Gutenberg blocks as HTML structured data rather than JSON data, then using the WPGraphQL Content Blocks plugin would be recommended. This would allow for the decoupled app, to easily render the blocks via the `dangerouslySetInnerHTML` method rather than having to individually design each block's corresponding component.

That being said, we intend to get this feature included in the VIP Block Data API plugin in the near future. This would allow for the eventual deprecation of the WPGraphQL Content Block plugin.

## Contributing

Expand Down
26 changes: 26 additions & 0 deletions lib/vip-block-data-api/.editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# This file is for unifying the coding style for different editors and IDEs
# It is based on https://core.trac.wordpress.org/browser/trunk/.editorconfig
# See https://editorconfig.org for more information about the standard.
# WordPress VIP documentation: https://docs.wpvip.com/technical-references/vip-codebase/editorconfig/

# WordPress Coding Standards
# https://make.wordpress.org/core/handbook/coding-standards/

root = true

[*]
charset = utf-8
end_of_line = lf
insert_final_newline = true
trim_trailing_whitespace = true
indent_style = tab

[*.yml]
indent_style = space
indent_size = 2

[*.md]
trim_trailing_whitespace = false

[*.txt]
end_of_line = crlf
2 changes: 2 additions & 0 deletions lib/vip-block-data-api/.github/CODEOWNERS
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# See https://help.github.com/en/github/creating-cloning-and-archiving-repositories/about-code-owners
* @Automattic/vip-bistro
33 changes: 33 additions & 0 deletions lib/vip-block-data-api/.github/ISSUE_TEMPLATE/bug_report.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
---
name: Bug report
about: Create a report to help us improve
title: ''
labels: bug
assignees: ingeniumed, smithjw1, alecgeatches

---

**Describe the bug**
A clear and concise description of what the bug is.

**To Reproduce**
- Include what kind of a post has caused this problem
- Include any custom blocks that have caused this problem

**Expected behavior**
A clear and concise description of what you expected to happen.

**Actual behavior**
A clear and concise description of what actually happened.

**Block Data API URL**

If publicly accessible, please share the block data API URL used to reproduce this problem.

e.g. `https://my.site/wp-json/vip-block-data-api/v1/posts/139/blocks`

**Version of the plugin**
Version of the plugin

**Additional context**
Add any other context about the problem here. Please be careful to not share any confidential information here.
17 changes: 17 additions & 0 deletions lib/vip-block-data-api/.github/PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
## Description

A few sentences describing the overall goals of the Pull Request.

Should include any special considerations, decisions, and links to relevant GitHub issues.

## Steps to Test

Outline the steps to test and verify the PR here.

Example:

1. Check out PR.
1. Run `npm run build`.
1. Test the thing.`
1. Verify cookies are delicious.

43 changes: 43 additions & 0 deletions lib/vip-block-data-api/.github/workflows/phpcs.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
name: PHP CodeSniffer

on: pull_request

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

jobs:
build:
runs-on: ubuntu-latest

strategy:
matrix:
php-versions:
- 8.0

steps:
- uses: actions/checkout@v2

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
tools: composer
php-version: ${{ matrix.php-versions }}

- name: Validate composer.json and composer.lock
run: composer validate --strict

- name: Cache Composer packages
id: composer-cache
uses: actions/cache@v2
with:
path: vendor
key: ${{ runner.os }}-php-${{ hashFiles('**/composer.lock') }}
restore-keys: |
${{ runner.os }}-php-

- name: Install dependencies
run: composer install --prefer-dist --no-progress

- name: PHPCS
run: composer run-script phpcs
59 changes: 59 additions & 0 deletions lib/vip-block-data-api/.github/workflows/phpunit.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
name: PHPUnit

on: pull_request

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

jobs:
build:
runs-on: ubuntu-latest

strategy:
matrix:
php-versions:
- 8.0

env:
DB_DATABASE: test_db
DB_USER: root
DB_PASSWORD: root

steps:
- name: Checkout
uses: actions/checkout@v2

- name: Install wordpress environment
run: npm -g install @wordpress/env

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
tools: composer
php-version: ${{ matrix.php-versions }}

- name: Setup MySQL
run: |
sudo /etc/init.d/mysql start

- name: Cache Composer packages
id: composer-cache
uses: actions/cache@v2
with:
path: vendor
key: ${{ runner.os }}-php-${{ hashFiles('**/composer.lock') }}
restore-keys: |
${{ runner.os }}-php-

- name: Install dependencies
run: composer install --prefer-dist --no-progress

- name: Setup the wordpress environment
run: wp-env start

- name: PHPUnit
run: composer test

- name: PHPUnit multisite
run: composer run-script test-multisite
8 changes: 8 additions & 0 deletions lib/vip-block-data-api/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
vip-block-data-api*.zip

# Ignore non-production composer dependencies
vendor/*
!vendor/autoload.php
!vendor/composer/
!vendor/masterminds/
!vendor/symfony/
5 changes: 5 additions & 0 deletions lib/vip-block-data-api/.wp-env.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"plugins": [
"."
]
}
Loading
Loading