Publish - WunderGraph

Usage

npx wgc router plugin publish [directory]

Prerequisites: Before publishing, you must first scaffold your plugin using npx wgc router plugin init <name> to create the required directory structure and files.

Publish is an irreversible action. However, the change will only be visible to the routers once the composition has been successful. Until then, the routers will operate with the most recent valid composition. Please use subgraph check to understand the impact of your change.

Description

The npx wgc router plugin publish command enables you to publish a plugin subgraph to the Cosmo platform. Publishing a plugin subgraph makes it available for use by federated graphs, allowing them to extend functionality through custom plugins. The command builds and pushes a Docker image containing your plugin to the registry, then publishes the subgraph schema to the control plane. The command expects a specific directory structure for your plugin and automatically locates the necessary files within the plugin directory. The plugin name is derived from the directory name. You should first run npx wgc router plugin init <name> to scaffold the proper directory structure.

Parameters

Options

Plugin Directory Structure

The plugin directory must contain the following files in their expected locations (created automatically by npx wgc router plugin init):

Optional Options

If the plugin subgraph has already been created previously, the label parameter will be ignored. Use subgraph update to update these values.

If you are creating a plugin subgraph for the first time with router plugin publish, the label parameter can be used to set labels. Note that a subgraph will only be considered for a federated graph composition if the subgraph’s labels match the labels matcher of that federated graph. If you are not creating a plugin subgraph for the first time, the label parameter will be ignored. To update the labels of an existing plugin subgraph, use subgraph update.

Examples

Publish a plugin subgraph

npx wgc router plugin publish ./plugins/my-plugin

Create and publish a plugin subgraph with labels and multi-platform support

npx wgc router plugin publish ./plugins/my-plugin \
  --label team=backend --label environment=production \
  --platform linux/amd64 linux/arm64

Publish with custom name

If the plugin name is not provided, the name will be derived from the directory name. This is mainly used to publish plugin feature subgraphs, as the directory will still be the base subgraph.

npx wgc router plugin publish ./plugins/my-plugin \
  --name my-custom-name

Publish with custom namespace

npx wgc router plugin publish ./plugins/my-plugin \
  --namespace production

Typical Workflow

Here’s the recommended workflow for developing and publishing a plugin:

  1. Initialize the plugin:
npx wgc router plugin init my-plugin

This creates the plugin in the plugins/my-plugin/ directory. 2. Develop your plugin: Modify the generated files as needed:

  1. Test your plugin locally: Use the generated Makefile commands to build and test
  2. Publish the plugin:
# Option 1: Specify the directory path
npx wgc router plugin publish ./plugins/my-plugin

# Option 2: Run from within the plugin directory
cd ./plugins/my-plugin
npx wgc router plugin publish

Docker Requirements

Docker Buildx with a container builder is required for publishing plugins.

Recommended Installation

Before publishing plugins, ensure you have:

To verify your setup, run:

docker buildx version
docker buildx inspect

Important: The docker buildx inspect output must show the docker-container driver. If you don’t see this, create a builder:

docker buildx create --name container-builder --use
docker buildx inspect --bootstrap

Build Process

The publish command performs the following steps:

  1. Validation: Validates that all required files exist in the plugin directory at their expected locations
  2. Image Build: Builds the Docker image using docker buildx build with the specified platforms
  3. Image Push: Pushes the built image to the plugin registry
  4. Schema Publish: Publishes the GraphQL schema to the control plane

Notes

my-plugin/
├── src/
│   └── schema.graphql
├── generated/
│   ├── service.proto
│   ├── mapping.json
│   └── service.proto.lock.json
└── Dockerfile