axepress/wp-graphql-plugin-boilerplate

创建 WPGraphQL 扩展的样板代码

0.1.0 2024-04-06 17:12 UTC

README

Logo

WPGraphQL 插件样板

🚨 注意:这是预发布软件。自行承担风险 🚨

创建 WPGraphQL 扩展的样板代码。可以作为 Composer 依赖项使用,也可以作为构建自己的插件的工具。

受以下项目和它们的贡献者启发

功能

系统要求

  • PHP 7.4+ | 8.0+ | 8.1+
  • WordPress 5.4.1+
  • WPGraphQL 1.8.0+

入门指南

作为 Composer 依赖项

我们建议使用 Strauss 安装此样板,以防止插件与其他库发生冲突。更多信息请参阅此 来自 StellarWP 的说明

1. 将依赖项添加到您的项目中。

composer require axewp/wp-graphql-plugin-boilerplate

2. 配置 Strauss。

  1. 将以下脚本添加到 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"
  ]
}
  1. 将 strauss 配置添加到 composer.json 的 "extra" 中
"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": []
    }
  }
},
  1. 将自动加载器包含在 composer.json 的 classmap 中。
"autoload": {
  "files": [
    "access-functions.php"
  ],
  "psr-4": {
    "WPGraphQL\\PluginName\\": "src/"
  },
+  "classmap": [
+    "vendor-prefixed/"
+  ]
},

作为插件起点

1. 初始化插件

创建您的 WPGraphQL 插件就像将项目下载到您的机器上并运行 curl -fsSL https://raw.github.com/AxeWP/wp-graphql-plugin-boilerplate/master/bin/install.sh | bash 一样简单。

您将需要提供以下配置详细信息,或者您可以将它们作为标志传递。

  • 分支 (--branch) : 使用的 Github 分支作为源。
  • 名称 (--name) : 您插件的名称(例如 My Plugin for WPGraphQL)。
  • 命名空间 (--namespace): 用于插件的 PHP 命名空间(例如 MyPlugin)。
  • 路径 (--path): 插件应创建的目录路径(例如 mysite/wp-content/plugins)。
  • 前缀 (--prefix): 插件前缀(蛇形命名)。这将用于生成唯一的函数、钩子和常量(例如 my_plugin)。
  • 短网址 (--slug): 用于插件的短网址(斜杠命名)。例如 wp-graphql-my-plugin

或者,您可以下载仓库并运行 composer create-plugin

2. 创建您的 .env 文件

.env.dist 重命名为 .env,并将变量设置为您的特定 localhost/testing 环境。

项目结构
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

路线图

  • 包含示例文件。
  • 提升生活质量的实用工具,使扩展 WPGraphQL 变得容易。
  • 详尽的文档。

文档

@待办事项

食谱

@待办事项