Init
Scaffold a new gRPC router plugin
wgc router grpc-plugin init
The init
command scaffolds a new gRPC router plugin project with all the necessary files and directory structure.
Usage
Arguments
Argument | Description |
---|---|
name | Name of the plugin |
Options
Option | Description | Default |
---|---|---|
-p, --project <project> | The name of the project | cosmo |
-d, --directory <directory> | Directory to create the plugin in | . (current directory) |
-l, --language <language> | Programming language to use for the plugin | go |
--only-plugin | Creates only a plugin without bootstrapping a full router project | false |
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
) - Go implementation files (
src/main.go
,src/main_test.go
) - Generated protocol files (
generated/service.proto
) - Go module configuration (
go.mod
) - Documentation (
README.md
)
The scaffolded plugin includes a hello world example that you can customize according to your needs.
Directory Structure
After initialization, your project directory will have the following structure:
During later build steps, additional files will be generated:
generated/
: Contains generated Go code based on your schemabin/
: Contains compiled binaries for your plugin
You can also generate only the plugin without bootstrapping a full router project by using the --only-plugin
flag. This is useful if you want to create a plugin in an existing router project.
Examples
Basic usage
Specify a custom directory
Next Steps
After initializing your plugin, you should:
- Customize the GraphQL schema in
src/schema.graphql
- Generate the Go code with
make generate
- Implement your resolvers in
src/main.go
- Implement your tests in
src/main_test.go
and run them withmake test
- Build your plugin with
make build
For more information on these steps, see the build and test command documentation.