Skip to content

chore: Tidy up examples #304

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

Open
wants to merge 30 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
499ca6c
Moved examples for previews under "/examples" in the plugin directory…
colinmurphy Jun 30, 2025
beed62d
Fixed vendor directory for previews.
colinmurphy Jun 30, 2025
d94e6c6
Fix for e2e tests.
colinmurphy Jun 30, 2025
7c6ac68
Remove __MACOSX directory
colinmurphy Jul 1, 2025
7681502
Moved webhooks example under the plugin.
colinmurphy Jul 1, 2025
d38f637
Updated .gitignore to renove uplaods.zip rather than uploads and star…
colinmurphy Jul 1, 2025
e968d34
chore: cleanup part 1
ahuseyn Jul 1, 2025
168e277
chore: custom-sitemap-apollo update
ahuseyn Jul 1, 2025
a8a502e
chore: clean up part 2
ahuseyn Jul 1, 2025
d59b4c7
chore: cleanup part 3
ahuseyn Jul 1, 2025
008b60e
Merge branch 'main' into chore-update-examples-iteration-1
colinmurphy Jul 1, 2025
bd3a1c5
fix: instructions and styles fix for proxied-graphql-debug
ahuseyn Jul 2, 2025
e4d072e
chore: cleanup after tests
ahuseyn Jul 3, 2025
b969cf2
Updated ACF version.
colinmurphy Jul 4, 2025
369a58f
docs: update examples readme, add best practices guide
ahuseyn Jul 4, 2025
165c61a
fix: nuxt example package and wp-env fixes
ahuseyn Jul 4, 2025
4be9f93
Merge branch 'chore-update-examples-iteration-1' of https://github.co…
ahuseyn Jul 4, 2025
6ab32de
Merge branch 'main' into chore-update-examples-iteration-1
ahuseyn Jul 8, 2025
0f0bf5d
Merge branch 'main' into chore-update-examples-iteration-1
colinmurphy Jul 9, 2025
ede4bd5
fix: update .gitignore, bring uploads.zip back, ignore uploads folder
ahuseyn Jul 11, 2025
72413fd
fix: apollo-client-data-fetch uploads.zip add
ahuseyn Jul 11, 2025
91fabb5
fix: apollo-client-filesystem-routing uploads.zip add
ahuseyn Jul 11, 2025
f1b7baf
fix: client-app-router-fetch-data uploads.zip add
ahuseyn Jul 11, 2025
929d39e
fix: custom-sitemap-apollo uploads.zip add
ahuseyn Jul 11, 2025
a8bc9b3
fix: custom-sitemap-vanilla-wpgraphql uploads.zip add
ahuseyn Jul 11, 2025
e89642a
fix: client-multisite-app-router-fetch-data uploads.zip add
ahuseyn Jul 11, 2025
a54c707
fix: template-hierarchy-data-fetching-urql uploads.zip add
ahuseyn Jul 11, 2025
da28655
Merge pull request #334 from wpengine/chore-update-examples-iteration-2
ahuseyn Jul 11, 2025
a945c49
chore: remove uploads from plugin examples
ahuseyn Jul 11, 2025
63b7396
fix: fix .gitignore to preserve example .sql files
ahuseyn Jul 11, 2025
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
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ test-results/
.wp-env.override.json
uploads/
debug.log
__MACOSX

# Environment
.env
Expand All @@ -27,4 +28,5 @@ debug.log

## Examples
examples/**/package-lock.json
examples/**/__MACOSX
examples/**/__MACOSX
``
116 changes: 99 additions & 17 deletions examples/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,31 +12,113 @@ This directory contains examples demonstrating how to use various features of th

## Next.js Examples

| Title | Description |
| ------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------ |
| [apollo-authentication](next/apollo-authentication) | Showcases authentication with Next.js, Apollo Client, and Headless WordPress. |
| [apollo-client-data-fetch](next/apollo-client-data-fetch) | Explores data fetching strategies and state management using Next.js, Apollo Client, and Headless WordPress. |
| [apollo-client-filesystem-routing](next/apollo-client-filesystem-routing) | Integrates WPGraphQL and WPGraphQL for ACF with Next.js for a headless WordPress site. |
| [client-app-router-fetch-data](next/client-app-router-fetch-data) | Uses Next.js App Router and fetch API to retrieve data from WordPress via WPGraphQL. |
| [client-multisite-app-router-fetch-data](next/client-multisite-app-router-fetch-data) | Implements a multisite headless WordPress app with Next.js App Router and fetch API. |
| [custom-sitemap-apollo](next/custom-sitemap-apollo) | Generates a custom sitemap using Next.js, Apollo Client, and WPGraphQL with an extended plugin. |
| [custom-sitemap-vanilla-wpgraphql](next/custom-sitemap-vanilla-wpgraphql) | Creates a custom sitemap using Next.js and WPGraphQL without extending its endpoints. |
| [hybrid-sitemap-apollo](next/hybrid-sitemap-apollo) | Fetches and transforms WordPress sitemaps for clean URL formatting with Next.js. |
| [proxied-sitemap-apollo](next/proxied-sitemap-apollo) | Provides a proxied sitemap by transforming WordPress XML sitemaps for SEO-friendly frontend URLs. |
| [proxied-graphql-debug](next/proxied-graphql-debug) | Provides a proxied GraphQL API for development, enabling response inspection and query complexity analysis. |
| [render-blocks-pages-router](next/render-blocks-pages-router) | Renders WordPress Blocks with JSX in Next.js, including utilities for hierarchical block data. |
| Title | Description |
| ------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------- |
| [apollo-authentication](next/apollo-authentication) | Showcases authentication with Next.js, Apollo Client, and Headless WordPress. |
| [apollo-client-data-fetch](next/apollo-client-data-fetch) | Explores data fetching strategies and state management using Next.js, Apollo Client, and Headless WordPress. |
| [apollo-client-filesystem-routing](next/apollo-client-filesystem-routing) | Integrates WPGraphQL and WPGraphQL for ACF with Next.js for a headless WordPress site. |
| [client-app-router-fetch-data](next/client-app-router-fetch-data) | Uses Next.js App Router and fetch API to retrieve data from WordPress via WPGraphQL. |
| [client-multisite-app-router-fetch-data](next/client-multisite-app-router-fetch-data) | Implements a multisite headless WordPress app with Next.js App Router and fetch API. |
| [custom-sitemap-apollo](next/custom-sitemap-apollo) | Generates a custom sitemap using Next.js, Apollo Client, and WPGraphQL with an extended plugin. |
| [custom-sitemap-vanilla-wpgraphql](next/custom-sitemap-vanilla-wpgraphql) | Creates a custom sitemap using Next.js and WPGraphQL without extending its endpoints. |
| [hybrid-sitemap-apollo](next/hybrid-sitemap-apollo) | Fetches and transforms WordPress sitemaps for clean URL formatting with Next.js. |
| [proxied-sitemap-apollo](next/proxied-sitemap-apollo) | Provides a proxied sitemap by transforming WordPress XML sitemaps for SEO-friendly frontend URLs. |
| [proxied-graphql-debug](next/proxied-graphql-debug) | Provides a proxied GraphQL API for development, enabling response inspection and query complexity analysis. |
| [render-blocks-pages-router](next/render-blocks-pages-router) | Renders WordPress Blocks with JSX in Next.js, including utilities for hierarchical block data. |
| [wp-theme-rendered-blocks](next/wp-theme-rendered-blocks) | Demonstrates how to fetch and apply WordPress Global Styles in a Next.js project using the `globalStylesheet` GraphQL field. |

## SvelteKit Examples

| Title | Description |
| ---------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------- |
| [template-hierarchy-data-fetching-urql](sveltekit/template-hierarchy-data-fetching-urql) | Demonstrates template hierarchy and data fetching with SvelteKit, URQL, and Headless WordPress. |
| [wp-theme-rendered-blocks](next/wp-theme-rendered-blocks) | Demonstrates how to fetch and apply WordPress Global Styles in a Next.js project using the `globalStylesheet` GraphQL field. |
| Title | Description |
| ---------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------- |
| [template-hierarchy-data-fetching-urql](sveltekit/template-hierarchy-data-fetching-urql) | Demonstrates template hierarchy and data fetching with SvelteKit, URQL, and Headless WordPress. |

## Nuxt Examples

| Title | Description |
| ------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| [nuxt-headlesswp-gravity-forms](nuxt/nuxt-headlesswp-gravity-forms) | Shows you how to wire up a full headless WordPress backend—complete with Gravity Forms, WPGraphQL, and a pre-built "Questionnaire" form—alongside a Nuxt 3 front end. |

## Contributing

If you feel like something is missing or you want to add an example for another framework, we encourage you to contribute! Please check out our [Contributing Guide](https://github.com/wpengine/hwptoolkit/blob/main/CONTRIBUTING.md) for more details.

### Best practices for the new examples

You can copy on of existing examples to use it as a _skeleton_ of your new example. The guide below explains the key parts our standard example format.

1. **Project Structure**

Organize your project with a clear separation between the frontend application and the WordPress environment configuration.

```bash
.
├── example-app/ # Front-end code
│ └── ...
├── .wp-env.json # Configuration for the local WordPress environment
└── wp-env/
└── db/
└── database.sql # Initial database state
```

2. **Local WordPress with wp-env**

Use wp-env to create a local, containerized WordPress environment. Create a .wp-env.json file in your project root and include all of the required plugins and config to make your example work:

```json
{
"phpVersion": "7.4",
"plugins": ["https://github.com/wp-graphql/wp-graphql/releases/latest/download/wp-graphql.zip"],
"config": {
"WP_DEBUG": true
},
"mappings": {
"db": "./wp-env/db",
"wp-content/uploads": "./wp-env/uploads",
".htaccess": "./wp-env/setup/.htaccess"
},
"lifecycleScripts": {
"afterStart": "wp-env run cli -- wp rewrite structure '/%postname%/' && wp-env run cli -- wp rewrite flush"
}
}
```

3. **Scripts**

Scripts in your package.json help automate common tasks. You can use our standard scripts to achieve the recommended workflow..

```json
"scripts": {
"example:build": "npm run example:dev:install && npm run wp:start && npm run wp:db:import && npm run example:start",
"example:dev:install": "cd example-app && npm install && cd ..",
"example:start": "npm run wp:start && npm run example:dev",
"example:stop": "npm run wp:stop",
"example:prune": "wp-env destroy && npm run example:build && npm run example:start",
"example:dev": "npm --prefix ./example-app run dev",
"wp:start": "npm install && wp-env start",
"wp:stop": "wp-env stop",
"wp:destroy": "wp-env destroy --config ./wp-env/wp-env.json",
"wp:db:query": "wp-env run cli -- wp db query",
"wp:db:export": "wp-env run cli -- wp db export /var/www/html/db/database.sql",
"wp:db:import": "wp-env run cli -- wp db import /var/www/html/db/database.sql",
"wp-env": "wp-env"
},
```

4. **Documentation (README.md)**

A clear README.md with essential information would guide the new developers effectively and reduce the errors. Consider including the information below:

- Prerequisites: Node.js, Docker.

- Setup Steps: A simple list on how to clone, install dependencies, and run the start script.

- Demo Credentials: Provide login details for the local WordPress admin (/wp-admin). Default for wp-env is admin / password.

- Security implications, and other considerations for the users, if applicable.

- Don't forget to include your example to this common README file as well, inside one of the tables above.

## Screenshots

> **Feature Highlight:** Here are some sample screenshots of the examples listed above.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"version": "0.0.1",
"scripts": {
"example:bootstrap": "npm install & npm run app:install",
"example:start": "pnpm run wp:start && npm run app:dev",
"example:start": "npm run wp:start && npm run app:dev",
"example:setup": "npm run example:bootstrap && npm run wp:start && npm run wp:db:import && npm run example:stop",
"example:stop": "npm run wp:stop",
"example:prune": "npm run wp:destroy && npm run example:setup && npm run example:start",
Expand Down
3 changes: 0 additions & 3 deletions examples/next/apollo-authentication/.gitignore

This file was deleted.

5 changes: 1 addition & 4 deletions examples/next/apollo-authentication/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ echo "NEXT_PUBLIC_WORDPRESS_URL=http://localhost:8888" > examples/next/apollo-au
- `cd examples/next/apollo-authentication`
- Then run `npm run example:build` will build and start your application.
- This does the following:
- Unzips `wp-env/uploads.zip` to `wp-env/uploads` which is mapped to the wp-content/uploads directory for the Docker container.
- Starts up [wp-env](https://developer.wordpress.org/block-editor/getting-started/devenv/get-started-with-wp-env/)
- Imports the database from [wp-env/db/database.sql](wp-env/db/database.sql)
- Install Next.js dependencies for `example-app`
Expand All @@ -73,7 +72,7 @@ Congratulations, WordPress should now be fully set up.

| Command | Description |
| --------------------- | ----------------------------------------------------------------------------------------------------------------------- |
| `example:build` | Prepares the environment by unzipping images, starting WordPress, importing the database, and starting the application. |
| `example:build` | Prepares the environment by starting WordPress, importing the database, and starting the application. |
| `example:dev` | Runs the Next.js development server. |
| `example:dev:install` | Installs the required Next.js packages. |
| `example:start` | Starts WordPress and the Next.js development server. |
Expand All @@ -85,8 +84,6 @@ Congratulations, WordPress should now be fully set up.
| `wp:db:query` | Executes a database query within the WordPress environment. |
| `wp:db:export` | Exports the WordPress database to `wp-env/db/database.sql`. |
| `wp:db:import` | Imports the WordPress database from `wp-env/db/database.sql`. |
| `wp:images:unzip` | Extracts the WordPress uploads directory. |
| `wp:images:zip` | Compresses the WordPress uploads directory. |

> **Note** You can run `npm run wp-env` and use any other wp-env command. You can also see <https://www.npmjs.com/package/@wordpress/env> for more details on how to use or configure `wp-env`.
Expand Down
2 changes: 0 additions & 2 deletions examples/next/apollo-authentication/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@
"wp:db:query": "wp-env run cli -- wp db query",
"wp:db:export": "wp-env run cli -- wp db export /var/www/html/db/database.sql",
"wp:db:import": "wp-env run cli -- wp db import /var/www/html/db/database.sql",
"wp:images:unzip": "rm -rf wp-env/uploads/ && unzip wp-env/uploads.zip -d wp-env;",
"wp:images:zip": "zip -r wp-env/uploads.zip wp-env/uploads",
"wp-env": "wp-env"
},
"keywords": [
Expand Down
15 changes: 5 additions & 10 deletions examples/next/apollo-client-data-fetch/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,24 +53,22 @@ This example demonstrates various approaches to integrate WordPress as a headles
└── wp-env
├── db
│ └── database.sql # WordPress database including all demo data for
├── setup
└── uploads.zip # WordPress content to be used by wp-env
└── setup
```

## Running the example with wp-env

### Prerequisites

- Node.js (v18+ recommended)
- [pnpm](https://pnpm.io/)
- [Docker](https://www.docker.com/) (if you plan on running the example see details below)

**Note** Please make sure you have all prerequisites installed as mentioned above and Docker running (`docker ps`)

### Setup Repository and Packages

- Clone the repo `git clone https://github.com/wpengine/hwptoolkit.git`
- Install packages `cd hwptoolkit && pnpm install`
- Install packages `cd hwptoolkit && npm install`
- Setup a .env file under `examples/next/apollo-client-data-fetch/example-app` and add these values inside:

```bash
Expand All @@ -87,9 +85,8 @@ echo "NEXT_PUBLIC_WORDPRESS_URL=http://localhost:8888\\nNEXT_PRIVACY_POLICY_URI=
### Build and start the application

- `cd examples/next/apollo-client-data-fetch`
- Then run `pnpm example:build` will build and start your application.
- Then run `npm run example:build` will build and start your application.
- This does the following:
- Unzips `wp-env/uploads.zip` to `wp-env/uploads` which is mapped to the wp-content/uploads directory for the Docker container.
- Starts up [wp-env](https://developer.wordpress.org/block-editor/getting-started/devenv/get-started-with-wp-env/)
- Imports the database from [wp-env/db/database.sql](wp-env/db/database.sql)
- Install Next.js dependencies for `example-app`
Expand All @@ -107,7 +104,7 @@ Congratulations, WordPress should now be fully set up.

| Command | Description |
| --------------------- | ----------------------------------------------------------------------------------------------------------------------- |
| `example:build` | Prepares the environment by unzipping images, starting WordPress, importing the database, and starting the application. |
| `example:build` | Prepares the environment by starting WordPress, importing the database, and starting the application. |
| `example:dev` | Runs the Next.js development server. |
| `example:dev:install` | Installs the required Next.js packages. |
| `example:start` | Starts WordPress and the Next.js development server. |
Expand All @@ -119,10 +116,8 @@ Congratulations, WordPress should now be fully set up.
| `wp:db:query` | Executes a database query within the WordPress environment. |
| `wp:db:export` | Exports the WordPress database to `wp-env/db/database.sql`. |
| `wp:db:import` | Imports the WordPress database from `wp-env/db/database.sql`. |
| `wp:images:unzip` | Extracts the WordPress uploads directory. |
| `wp:images:zip` | Compresses the WordPress uploads directory. |

> **Note** You can run `pnpm wp-env` and use any other wp-env command. You can also see <https://www.npmjs.com/package/@wordpress/env> for more details on how to use or configure `wp-env`.
> **Note** You can run `npm run wp-env` and use any other wp-env command. You can also see <https://www.npmjs.com/package/@wordpress/env> for more details on how to use or configure `wp-env`.

### Database access

Expand Down
Loading
Loading