Skip to content

feat: add docs for gRPC services #102

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

Draft
wants to merge 13 commits into
base: main
Choose a base branch
from
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ description: 'Build a gRPC router plugin'
icon: 'hammer'
---

# wgc router plugin build
# wgc router grpc-plugin build

The `build` command generates gRPC code based on your GraphQL schema and compiles your plugin into platform-specific binaries.

## Usage

```bash
wgc router plugin build [options] [directory]
wgc router grpc-plugin build [options] [directory]
```

## Arguments
Expand Down Expand Up @@ -63,25 +63,25 @@ You can also install the dependencies manually and use an IDE with Go support. T
### Build for the current platform

```bash
wgc router plugin build ./my-plugin
wgc router grpc-plugin build ./my-plugin
```

### Generate code only

```bash
wgc router plugin build --generate-only ./my-plugin
wgc router grpc-plugin build --generate-only ./my-plugin
```

### Build for multiple platforms

```bash
wgc router plugin build --platform darwin-arm64 linux-amd64 ./my-plugin
wgc router grpc-plugin build --platform darwin-arm64 linux-amd64 ./my-plugin
```

### Build for all supported platforms

```bash
wgc router plugin build --all-platforms ./my-plugin
wgc router grpc-plugin build --all-platforms ./my-plugin
```

## Supported Platforms
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ description: 'Scaffold a new gRPC router plugin'
icon: 'file-circle-plus'
---

# wgc router plugin init
# wgc router grpc-plugin init

The `init` command scaffolds a new gRPC router plugin project with all the necessary files and directory structure.

## Usage

```bash
wgc router plugin init [options] <name>
wgc router grpc-plugin init [options] <name>
```

## Arguments
Expand Down Expand Up @@ -83,13 +83,13 @@ You can also generate only the plugin without bootstrapping a full router projec
### Basic usage

```bash
wgc router plugin init users
wgc router grpc-plugin init users
```

### Specify a custom directory

```bash
wgc router plugin init users -d ./plugins
wgc router grpc-plugin init users -d ./plugins
```

## Next Steps
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ description: 'Run tests for a gRPC router plugin'
icon: 'vial'
---

# wgc router plugin test
# wgc router grpc-plugin test

The `test` command runs tests for your gRPC router plugin to verify its functionality.

## Usage

```bash
wgc router plugin test [options] [directory]
wgc router grpc-plugin test [options] [directory]
```

## Arguments
Expand Down Expand Up @@ -65,7 +65,7 @@ The default test file tests the plugin's ability to handle basic GraphQL queries
### Run tests for a plugin

```bash
wgc router plugin test ./my-plugin
wgc router grpc-plugin test ./my-plugin
```

## Best Practices
Expand Down
16 changes: 16 additions & 0 deletions docs/cli/router/grpc-service.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
---
title: "gRPC Service"
icon: network-wired
sidebarTitle: Overview
description: "Commands for working with gRPC services for the Cosmo Router"
---

WunderGraph Cosmo CLI includes commands for working with gRPC services for the Cosmo Router.

<CardGroup>
<Card title="Generate" href="/cli/router/grpc-service/generate" icon="code">
Generate a protobuf definition and mapping file for a gRPC service from a GraphQL schema
</Card>
</CardGroup>

For detailed documentation about gRPC services and how they work, see the [Router gRPC Services](/router/grpc/grpc-services) documentation.
68 changes: 68 additions & 0 deletions docs/cli/router/grpc-service/generate.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
---
title: "Generate"
icon: code
sidebarTitle: Generate
description: "Generate a protobuf definition for a gRPC service from a GraphQL schema"
---

# wgc router grpc-service generate

The `generate` command generates a protobuf definition and mapping file for a gRPC service from a GraphQL schema,
which can be used to implement a gRPC service and can be used for the composition.

## Usage

```bash
wgc router grpc-service generate [options] [service-name]
```

## Arguments

| Argument | Description | Default |
|----------|-------------|---------|
| `service-name` | Name of the gRPC service | `service.v1` |

## Options

| Option | Description | Default |
|--------|-------------|---------|
| `-i, --input <path-to-input>` | The GraphQL schema file to generate a protobuf schema from | Required |
| `-o, --output <path-to-output>` | The output directory for the protobuf schema | `.` |
| `-p, --package-name <name>` | The name of the proto package | `service.v1` |
| `-g, --go-package <name>` | Adds an `option go_package` to the proto file | None |

## Description

This command generates a protobuf definition for a gRPC service from a GraphQL schema.

## Examples

### Generate a protobuf definition for a gRPC service from a GraphQL schema

```bash
wgc router grpc-service generate -i ./schema.graphql -o ./service MyService
```

### Define a custom package name

```bash
wgc router grpc-service generate -i ./schema.graphql -o ./service MyService --package-name my.custom.package
```

### Define a custom go package name

```bash
wgc router grpc-service generate -i ./schema.graphql -o ./service MyService --go-package github.com/wundergraph/cosmo/service/my-service
```

## Output

The command generates multiple files in the output directory:

- `service.proto`: The protobuf definition for the gRPC service
- `service.mapping.json`: The mapping file for the gRPC service
- `service.proto.lock.json`: The lock file for the protobuf definition

The generated protobuf definition can be used to implement a gRPC service in any language that supports protobuf.

The mapping and the protobuf definition is needed for the composition part.
32 changes: 23 additions & 9 deletions docs/docs.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@
"tutorial/using-persisted-operations",
"tutorial/using-apollo-router-gateway-with-cosmo-oss-schema-registry",
"tutorial/supergraph-previews-for-every-pull-request",
"tutorial/gradual-and-experimental-feature-rollout-with-feature-flags"
"tutorial/gradual-and-experimental-feature-rollout-with-feature-flags",
"tutorial/grpc-service-quickstart"
]
}
]
Expand Down Expand Up @@ -218,13 +219,21 @@
]
},
{
"group": "Plugin",
"group": "gRPC Plugin",
"icon": "plug",
"pages": [
"cli/router/plugin",
"cli/router/plugin/init",
"cli/router/plugin/build",
"cli/router/plugin/test"
"cli/router/grpc-plugin",
"cli/router/grpc-plugin/init",
"cli/router/grpc-plugin/build",
"cli/router/grpc-plugin/test"
]
},
{
"group": "gRPC Service",
"icon": "network-wired",
"pages": [
"cli/router/grpc-service",
"cli/router/grpc-service/generate"
]
}
]
Expand Down Expand Up @@ -398,9 +407,14 @@
"router/mcp",
"router/custom-modules",
{
"group": "Plugins",
"icon": "plug",
"pages": ["router/plugins", "router/plugins/debugging"]
"group": "gRPC",
"icon": "network-wired",
"pages": [
"router/gRPC/concepts",
"router/gRPC/grpc-services",
"router/gRPC/grpc-plugins",
"router/gRPC/debugging"
]
},
"router/authentication-and-authorization",
"router/advanced-data-privacy",
Expand Down
Loading