Publish - WunderGraph

Usage

wgc grpc-service publish <name> --schema <path-to-schema> --generated <path-to-generated-folder> [options]

Prerequisites: Before publishing, you must first generate your protobuf definitions using wgc grpc-service generate to create the required schema, mapping, and lock files.

Publish 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 to understand the impact of your change.

Description

The wgc grpc-service publish command enables you to publish a gRPC subgraph to the Cosmo platform. Publishing a gRPC subgraph makes it available for use by federated graphs, allowing them to extend functionality through gRPC service integration. If the gRPC subgraph doesn’t exist, it will be created automatically. If the publication leads to composition errors, the errors will be visible in the Studio. The router will continue to work with the latest valid schema. Consider using the wgc subgraph check command to check for composition errors before publishing.

Parameters

Options

Required Options

Optional Options

If the gRPC subgraph has already been created previously, the routing-url and label parameters will be ignored. Use subgraph update to update these values.

If you are creating a gRPC subgraph for the first time with grpc-service publish, the routing-url and label parameters can be used to set these values. Note that a subgraph will only be considered for a federated graph composition if the subgraph’s labels match the labels matcher of that federated graph. If you are not creating a gRPC subgraph for the first time, the routing-url and label parameters will be ignored. To update these values for an existing gRPC subgraph, use subgraph update.

Required Files

The generated folder must contain the following files (created automatically by wgc grpc-service generate):

Examples

Publish a gRPC subgraph

wgc grpc-service publish users-service \
  --schema ./src/schema.graphql \
  --generated ./generated

Create and publish a gRPC subgraph with routing URL and labels

wgc grpc-service publish users-service \
  --schema ./src/schema.graphql \
  --generated ./generated \
  --routing-url http://localhost:4001/graphql \
  --label team=backend environment=production

Publish with custom namespace

wgc grpc-service publish users-service \
  --schema ./src/schema.graphql \
  --generated ./generated \
  --namespace production

Publish with error handling flags

wgc grpc-service publish users-service \
  --schema ./src/schema.graphql \
  --generated ./generated \
  --fail-on-composition-error \
  --fail-on-admission-webhook-error

Typical Workflow

Here’s the recommended workflow for developing and publishing a gRPC subgraph:

  1. Create your GraphQL schema: Create a schema.graphql file with your GraphQL schema definition.
  2. Generate the protobuf definitions:
wgc grpc-service generate -i ./schema.graphql -o ./generated

This creates the required protobuf files: service.proto, mapping.json, and service.proto.lock.json. 3. Develop your gRPC service: Implement your service based on the generated protobuf definitions. 4. Test your service locally: Ensure your gRPC service works correctly. 5. Publish the subgraph:

wgc grpc-service publish users-service \
     --schema ./schema.graphql \
     --generated ./generated

Process Overview

The publish command performs the following steps:

  1. File Validation: Validates that the schema file and all required generated files exist and contain valid content.
  2. Subgraph Creation: Creates the subgraph if it doesn’t exist (using routing URL and labels if provided).
  3. Schema Publication: Publishes the GraphQL schema and protobuf definitions to the control plane.
  4. Composition: Triggers composition with other subgraphs in the federated graph.

Notes