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

ArgumentDescription
nameName of the plugin

Options

OptionDescriptionDefault
-p, --project <project>The name of the projectcosmo
-d, --directory <directory>Directory to create the plugin in. (current directory)
-l, --language <language>Programming language to use for the plugingo
--only-pluginCreates only a plugin without bootstrapping a full router projectfalse

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:

my-plugin/
├── cosmo/                        # Root project directory
│   ├── README.md                 # Project documentation
│   ├── Makefile                 # Makefile for your plugin
│   ├── config.yaml              # Router configuration
│   └── graph.yaml               # Supergraph configuration

└── plugins/                      # Plugins directory
    └── my-plugin/               # Your plugin directory
        ├── .cursor              # Cursor rules
        ├── README.md            # Documentation and getting started guide
        ├── Makefile            # Automation scripts
        ├── go.mod              # Go module definition
        ├── go.sum              # Go module sum

        ├── src/                # Source code directory
        │   ├── main.go         # Main implementation file
        │   └── main_test.go    # Test file

        └── generated/          # Generated files (do not edit)
            ├── mapping.json    # GraphQL to gRPC mapping
            ├── service.proto   # Protocol Buffers definition
            └── service.proto.lock.json  # Lock file for Proto generation

During later build steps, additional files will be generated:

  • generated/: Contains generated Go code based on your schema
  • bin/: 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

wgc router plugin init users

Specify a custom directory

wgc router plugin init users -d ./plugins

Next Steps

After initializing your plugin, you should:

  1. Customize the GraphQL schema in src/schema.graphql
  2. Generate the Go code with make generate
  3. Implement your resolvers in src/main.go
  4. Implement your tests in src/main_test.go and run them with make test
  5. Build your plugin with make build

For more information on these steps, see the build and test command documentation.