π¨ NOTE: This is prerelease software. Use at your own risk π¨
A boilerplate for creating WPGraphQL extensions. Can be used as a Composer dependency or as a tool to scaffold your own plugin.
Inspired by the following projects and their contributors:
- Default folder structure that mirrors WPGraphQL.
- Helper classes, interfaces, methods, and traits to make it easier to register new GraphQL types.
- Dependency management with Composer.
- Code sniffing with PHPCS, WordPress Coding Standards, and Automattic's WordPress VIP Coding Standards
- Static Analysis with PHPStan
- WPUnit Testing with Codeception and WPBrowser.
- Docker image generation.
- Automated CI with Github Actions.
- PHP 7.4+ | 8.0+ | 8.1+
- WordPress 5.4.1+
- WPGraphQL 1.8.0+
We recommend installing this boilerplate using Strauss, to prevent plugin conflicts with other libraries. For more information see this explainer from StellarWP.
composer require axewp/wp-graphql-plugin-boilerplate
- Add the following scripts to composer .json:
"scripts": {
"strauss": [
"test -f ./bin/strauss.phar || curl -o bin/strauss.phar -L -C - https://github.com/BrianHenryIE/strauss/releases/download/0.14.0/strauss.phar",
"@php bin/strauss.phar"
],
"post-install-cmd": [
"@strauss"
],
"post-update-cmd": [
"@strauss"
]
}
- Add the strauss config to "extra" in composer.json:
"extra": {
"strauss": {
"target_directory": "vendor-prefixed",
"namespace_prefix": "WPGraphQL\\PluginName\\Vendor\\",
"classmap_prefix": "WPGraphQL_PluginName",
"constant_prefix": "GRAPHQL_PLUGINNAME",
"include_modified_date": false,
"delete_vendor_files": true,
"packages": [
"axepress/wp-graphql-plugin-boilerplate"
],
"excluded_from_prefix": {
"file_patterns": []
}
}
},
- Include the autoloader in your composer.json's classmap.
"autoload": {
"files": [
"access-functions.php"
],
"psr-4": {
"WPGraphQL\\PluginName\\": "src/"
},
+ "classmap": [
+ "vendor-prefixed/"
+ ]
},
Creating your WPGraphQL plugin is as simple as downloading the project to your machine and running curl -fsSL https://raw.github.com/AxeWP/wp-graphql-plugin-boilerplate/master/bin/install.sh | bash
.
You will be asked to provide the following configuration details, or you can pass them as flags.
- Branch (
--branch
) : The Github branch to use as the source. - Name (
--name
) : The name of your plugin (e.g.My Plugin for WPGraphQL
). - Namespace (
--namespace
): The PHP namespace to be used for the plugin (e.g.MyPlugin
). - Path (
--path
): The path to the directory directory where the plugin should be created (e.g.mysite/wp-content/plugins
). - Prefix (
--prefix
): The plugin prefix (in snake case). This will be used to generate unique functions, hooks and constants (e.g.my_plugin
). - Slug (
--slug
): The slug (in kebab-case) to use for the plugin (e.g.wp-graphql-my-plugin
).
Alternatively, you can download the repository and run composer create-plugin
.
Rename .env.dist
to .env
, and set the variables to your particular localhost/testing environment.
wp-graphql-plugin-name # This will be renamed by `create-plugin` to the provided slug.
βββ .github/workflows
β βββ code-quality.yml # Github workflow for PHPStan.
β βββ code-standard.yml # Github workflow for PHPCS
β βββ integration-testing.yml # Github workflow for Codeception tests and Coveralls.
β βββ schema-linter.yml # Github workflow GraphQL schema linting.
β βββ upload-schema-artifact.yml # Generates a schema artifact on Github release, for use by schema-linter.yml
βββ .wordpress.org # Assets for use in WordPress's plugin directory.
βββ bin
β βββ _env.sh # The shared env variables used by other shell scripts.
β βββ _lib.sh # Shared functions used by other shell scripts
β βββ install-stan-env.sh # Creates a development environment for running PHPStan.
β βββ install-test-env.sh # Creates a development environment for running Codeception.
β βββ run-docker.sh # Builds and runs the Docker image.
β βββ wp-cli.yml # WPCLI configuration used for scripts.
βββ docker
β βββ app.Dockerfile
β βββ app.entrypoint.sh
β βββ app.post-setup.sh
β βββ app.setup.sh
β βββ testing.Dockerfile
β βββ testing.entrypoint.sh
βββ phpstan
β βββ constants.php # Stubbed plugin constants for PHPStan.
βββ src
β βββ Admin # Classes for modifying the WP dashboard.
β β βββ Settings
β β βββ Settings.php # Adds custom settings to WPGraphQL's settings page.
β βββ Connection # GraphQL connections.
β βββ Data
β βββ Fields # Individual GraphQL fields.
β βββ Model # GraphQL object data modelers.
β βββ Mutation # GraphQL mutations
β βββ Type # GraphQL types.
β β βββ Enum # Enum types.
β β βββ Input # Input types.
β β βββ Union # Union types.
β β βββ WPInterface # Interface types.
β β βββ WPObject # Object types.
β βββ Utils # Helper functions used across the plugin
β βββ CoreSchemaFilters.php # Entrypoint for modifying the default schema provided by WPGraphQL
β βββ Main.php # Bootstraps the plugin
β βββ TypeRegistry.php # Entrypoint for registering GraphQL types to the schema
βββ tests # Codeception tests
β βββ _data
β βββ _envs
β βββ _output
β βββ _support
β βββ acceptance
β βββ unit
β βββ wpunit
β βββ acceptance.suite.dist.yml
β βββ bootstrap.php
β βββ unit.suite.dist.yml
β βββ wpunit.suite.dist.yml
βββ vendor # Composer dependencies
β βββ composer/autoload.php # Composer autoloader
βββ vendor-prefixed # Namespaced dependencies, including the wrapped AxeWP classes from this package.
βββ .distignore
βββ .env.dist
βββ .gitattributes
βββ .gitignore
βββ .phpcs.xml.dist
βββ access-functions.php # Globally-available functions for accessing class methods.
βββ activation.php # Methods that run on plugin activation.
βββ codeception.dist.yml
βββ composer.json
βββ deactivation.php # Methods that run on plugin deactivation.
βββ docker-compose.yml
βββ LICENSE
βββ phpstan.neon.dist
βββ phpunit.xml.dist
βββ README.md # The repo readme file.
βββ readme.txt # The plugin readme file.
βββ wp-graphql-plugin-name.php
- Include example files.
- Quality-of-life utils that make it easy to extend WPGraphQL.
- Extensive documentation.
@todo
@todo