Init - WunderGraph
wgc router plugin init
The init command scaffolds a new gRPC router plugin project with all the necessary files and directory structure.
Usage
wgc router plugin init [options] <name>
Arguments
| Argument | Description |
|---|---|
name |
Name of the plugin |
Options
| Option | Description | Default |
|---|---|---|
-p, --project <project> |
Project name. When provided, a minimal router project is bootstrapped and the plugin is created at <project>/<name>. |
(none) |
-d, --directory <directory> |
Directory to create the plugin or project in | . (current directory) |
-l, --language <language> |
Programming language to use for the plugin (currently only go and ts is supported) |
go |
Description
This command creates a new plugin directory with the specified name and scaffolds the basic plugin structure, including:
A GraphQL schema file (
src/schema.graphql)Language specific implementation files
- For Go:
src/main.go,src/main_test.go - For TS:
src/plugin.ts,src/plugin.test.ts
- For Go:
Generated mapping and protocol files (
generated/mapping.json,generated/service.proto,generated/service.proto.lock.json)Language specific configuration (
go.mod)For Go:
go.mod- For TS:
package.json,tsconfig.json
- For TS:
Makefile and Dockerfile (
Makefile,Dockerfile)Documentation (
README.md)
When --project is provided, a minimal router project is created in the project directory with:
- Router configuration files in the project root (
config.yaml,graph.yaml) - Project-level files (
README.md,Makefile,.gitignore) - The plugin located at
<project>/<name>
If you want to create a plugin in an existing project directory, omit --project and use -d/--directory to choose where the plugin directory should be created.
Directory Structure
With --project
Go
my-project/
├── README.md # Project documentation
├── Makefile # Project Makefile
├── config.yaml # Router configuration
├── graph.yaml # Supergraph configuration
├── .gitignore
└── my-plugin/ # Your plugin directory
├── README.md
├── Makefile
├── go.mod
├── .gitignore
├── .cursorignore
├── .cursor/
│ └── rules/
│ └── plugin-development.mdc
├── src/
│ ├── schema.graphql
│ ├── main.go
│ └── main_test.go
├── generated/
│ ├── mapping.json
│ ├── service.proto
│ └── service.proto.lock.json
└── Dockerfile
TypeScript
my-project/
├── README.md # Project documentation
├── Makefile # Project Makefile
├── config.yaml # Router configuration
├── graph.yaml # Supergraph configuration
├── .gitignore
└── my-plugin/ # Your plugin directory
├── README.md
├── Makefile
├── package.json
├── tsconfig.json
├── .gitignore
├── .cursorignore
├── .cursor/
│ └── rules/
│ └── plugin-development.mdc
├── src/
│ ├── schema.graphql
│ ├── plugin.ts
│ ├── plugin-server.ts
│ └── plugin.test.ts
├── generated/
│ ├── mapping.json
│ ├── service.proto
│ └── service.proto.lock.json
└── Dockerfile
Without --project
The plugin is created directly under the chosen directory:
Go
my-plugin/
├── README.md
├── Makefile
├── go.mod
├── .gitignore
├── .cursorignore
├── .cursor/
│ └── rules/
│ └── plugin-development.mdc
├── src/
│ ├── schema.graphql
│ ├── plugin.ts
│ ├── plugin-server.ts
│ └── plugin.test.ts
├── generated/
│ ├── mapping.json
│ ├── service.proto
│ └── service.proto.lock.json
└── Dockerfile
TypeScript
my-plugin/
├── README.md
├── Makefile
├── package.json
├── tsconfig.json
├── .gitignore
├── .cursorignore
├── .cursor/
│ └── rules/
│ └── plugin-development.mdc
├── src/
│ ├── schema.graphql
│ ├── main.go
│ └── main_test.go
├── generated/
│ ├── mapping.json
│ ├── service.proto
│ └── service.proto.lock.json
└── Dockerfile
Examples
Basic usage
wgc router plugin init users
Create a new project and plugin
wgc router plugin init users -p cosmo
Specify a custom directory
wgc router plugin init users -d ./plugins
Next Steps
After initializing your plugin, you should:
- Customize the GraphQL schema in
src/schema.graphql - Generate code with
wgc router plugin generateormake generate - Implement your resolvers in
src/main.goorsrc/plugin.ts - Implement your tests in
src/main_test.goorsrc/plugin.test.tsand run them withmake test - Build your plugin with
make build