Skip to content

feat: add documentation for plugin commands #128

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
17 changes: 11 additions & 6 deletions docs/cli/feature-subgraph/create-feature-subgraph.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ Create a feature subgraph based on an existing subgraph for your federated graph

<Note>
A feature subgraph does not function in isolation. One or more feature subgraphs must compose a [feature flag](/cli/feature-flags), which itself must be enabled to take effect.

</Note>
```bash
wgc feature-subgraph create my-feature-subgraph --subgraph my-subgraph --routing-url http://localhost:4000
Expand All @@ -29,20 +28,20 @@ The alias for `feature-subgraph` is `fs`.

Note that unless specified by the `--namespace` parameter, the namespace will be automatically passed as "default".

<Note>
The type of the feature subgraph is determined by the type of the base subgraph. For example, if the base subgraph is a plugin subgraph, the feature subgraph will also be a plugin subgraph.
</Note>

## Parameters

* `<name>`: The name of the feature subgraph to create. Must be unique among all subgraphs and feature subgraphs within the specified (otherwise "default") namespace.

## Required Options

<Note>
If the routing URL is not supplied, or the base subgraph does not exist in the specified (otherwise "default") namespace, the command will fail.
If the base subgraph does not exist in the specified (otherwise "default") namespace, the command will fail.
</Note>

`-r , --routing-url`: Set the URL for the subgraph's data source. This URL defines the endpoint from which the subgraph will fetch data.

* Example: `--routing-url http://localhost:4001/graphql`

`--subgraph`: The name of the existing base subgraph for which the feature subgraph is to be created.

## Options
Expand All @@ -51,6 +50,12 @@ Note that unless specified by the `--namespace` parameter, the namespace will be
Feature subgraphs do not use labels directly; labels are set by the [feature flag](/cli/feature-flags) that the feature subgraph(s) compose.
</Info>

<Note>
If the base subgraph is not a plugin subgraph, the routing url is required.
</Note>

* `-r , --routing-url`: Set the URL for the subgraph's data source. This URL defines the endpoint from which the subgraph will fetch data.

* `-n, --namespace` : The namespace of the feature subgraph (defaults to "default"). Returns an error if the feature flag does not exist in that namespace.

* `--subscription-url:` Use a different URL for subscription requests. If no subscription URL is provided, the router URL is used for subscriptions.
Expand Down
58 changes: 58 additions & 0 deletions docs/cli/router/plugin/create.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
---
title: "Create"
description: "Creates a federated plugin subgraph on the control plane."
icon: plus
---

## Usage

<Note>
A plugin subgraph name must be unique within a namespace.
</Note>

```bash
npx wgc router plugin create [pluginName] --label [labelName]
```

<Info>
After creating a plugin subgraph, you can publish it with [wgc router plugin
publish](/cli/router/plugin/publish).
</Info>

## Description

The `npx wgc router plugin create` command allows you to create a new plugin subgraph within the Cosmo platform. Plugin subgraphs are specialized GraphQL schemas that extend the functionality of your federated graph through plugins. The `[pluginName]` argument specifies the name of the new plugin subgraph. Use `npx wgc router plugin create -h` to see all the available options.

## **Parameters**

- `[pluginName]`: The name of the plugin subgraph you want to create. It should be a unique identifier (within the namespace) and is used to uniquely identify your plugin subgraph.

## **Options**

- `-n, --namespace` : The namespace of the plugin subgraph (Default: "default").

- `--label`: Assign multiple labels to the new plugin subgraph. Labels are used to categorize and organize subgraphs based on specific criteria (e.g., team, department, project).

- Example: `--label team=A`

- `--readme <path-to-readme>:` The path to the markdown file which describes the plugin subgraph.

## **Examples**

- Create a new plugin subgraph named "projects" with the label "team=A":

```bash
npx wgc router plugin create projects --label team=A
```

- Create a new plugin subgraph with a readme file:

```bash
npx wgc router plugin create projects --label team=infrastructure --readme ./plugin-readme.md
```

- Create a plugin subgraph in a specific namespace:

```bash
npx wgc router plugin create projects --namespace production --label env=prod
```
62 changes: 62 additions & 0 deletions docs/cli/router/plugin/delete.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
---
title: "Delete"
description: "Deletes a plugin subgraph on the control plane. The plugin subgraph will be deleted from all federated graphs."
icon: trash
---

## Usage

```bash
npx wgc router plugin delete <name> [-f, --force]
```

<Note>
**Delete** 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](/cli/subgraph/check) to understand the impact of your change.
</Note>

## Description

The `npx wgc router plugin delete` command allows you to delete a plugin subgraph on the Cosmo platform's control plane. When you delete a plugin subgraph, all associated data and configurations will be permanently removed. Use this command with caution, as the action cannot be undone.

## Parameters

- `<name>`: The name of the plugin subgraph you want to delete. This should be the exact name of the plugin subgraph you wish to remove.

## Options

- `-n, --namespace` : The namespace of the plugin subgraph (Default: "default").

- `-f, --force`: An optional flag that allows you to force delete the plugin subgraph without being prompted for confirmation. Use this option if you want to delete the plugin subgraph without additional prompts.

- `--suppress-warnings`: This flag suppresses any warnings produced by composition.

## Examples

1. Delete the plugin subgraph named "projects":

```bash
npx wgc router plugin delete projects
```

2. Force delete the plugin subgraph named "projects" without confirmation:

```bash
npx wgc router plugin delete projects -f
```

3. Delete a plugin subgraph in a specific namespace:

```bash
npx wgc router plugin delete projects -n production
```

## Notes

- The `npx wgc router plugin delete` command interacts with the Cosmo platform's control plane to delete the specified plugin subgraph.

- When using the `--force` option, the command will not prompt for confirmation, so exercise caution to prevent accidental data loss.

- If composition errors occur during deletion, the plugin subgraph will still be deleted, but the router will continue to work with the latest valid schema until the composition issues are resolved.
90 changes: 90 additions & 0 deletions docs/cli/router/plugin/generate.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
---
title: "Generate"
description: "Generate proto and gRPC code for a router plugin"
icon: "code"
---

# wgc router plugin generate

The `generate` command creates Protocol Buffers definitions, mapping files, and gRPC code based on your GraphQL schema. This command is useful when you want to generate the necessary code without compiling binaries.

## Usage

```bash
wgc router plugin generate [directory] [options]
```

## Arguments

| Argument | Description | Default |
| ----------- | ----------------------- | ----------------------- |
| `directory` | Directory of the plugin | `.` (current directory) |

## Options

| Option | Description | Default |
| ---------------------------- | -------------------------------------------------------------------- | ------------------------------------- |
| `--go-module-path <path>` | Go module path to use for the plugin | `github.com/wundergraph/cosmo/plugin` |
| `--skip-tools-installation` | Skip tool installation | `false` |
| `--force-tools-installation` | Force tools installation regardless of version check or confirmation | `false` |

## Description

This command performs the code generation steps of the plugin build process:

1. **Generate Proto and Mapping Files**: Processes your GraphQL schema to generate Protocol Buffers definitions and mapping files
2. **Generate gRPC Code**: Uses the generated Proto files to create Go code for the gRPC service
3. **Install Go Dependencies**: Installs all required Go dependencies for your plugin

The `generate` command is equivalent to running [`build`](./build) with the `--generate-only` flag. Use this when you're iterating on your GraphQL schema and need to regenerate the code without compiling binaries.

## Required Tools

The generate command will automatically check for and install the necessary toolchain when required tools can't be found in the right version on your system. You can control this behavior with the `--skip-tools-installation` and `--force-tools-installation` flags.

You can also install the dependencies manually and use an IDE with Go support. The following table shows the current versions and download links for the required tools:

| Tool | Version | Installation Link |
| ------------------------- | -------------------------- | -------------------------------------------------------------------------- |
| Go | >=1.22.0 (Last 2 versions) | [Releases](https://go.dev/doc/install) |
| Protocol Buffers (protoc) | ^29.3 | [Releases](https://protobuf.dev/installation/) |
| protoc-gen-go | ^1.34.2 | [GitHub Releases](https://github.com/protocolbuffers/protobuf-go/releases) |
| protoc-gen-go-grpc | ^1.5.1 | [GitHub Releases](https://github.com/grpc/grpc-go/releases) |

## Examples

### Generate code for the current directory

```bash
wgc router plugin generate
```

### Generate code for a specific plugin directory

```bash
wgc router plugin generate ./my-plugin
```

### Generate with a custom Go module path

```bash
wgc router plugin generate --go-module-path github.com/myorg/my-plugin ./my-plugin
```

### Skip tool installation (useful in CI environments)

```bash
wgc router plugin generate --skip-tools-installation ./my-plugin
```

## Output

The generate process creates the following outputs:

- **Proto files**: Protocol Buffers definitions in the `generated/` directory
- **Mapping files**: Schema mapping files that connect your GraphQL schema to the gRPC service
- **Generated Go code**: gRPC client and server code in the `generated/` directory
- **Go dependencies**: All required dependencies will be installed in your Go module

After generating, you can continue development with your IDE or run [`build`](./build) to compile the plugin into binaries.

Loading