Check - WunderGraph

Usage

Check schema changes

npx wgc subgraph check <name> --schema <path-to-schema>

Use this command whenever you make modifications to your subgraphs. It will report any GraphQL or composition errors before they land on production. The report will be made visible under Schema Checks.

Check deletion of a subgraph

npx wgc subgraph check <name> --delete

This command will check any breaking changes or composition errors in case the subgraph is deleted.

Check how a new subgraph affects the federated graph

# There are two ways to check the impact of a new subgraph:

# 1. Create the subgraph and check the impact
npx wgc subgraph create products --label team=A --routing-url http://localhost:4001/graphql
npx wgc subgraph check <name> --schema schema.graphql

# 2. Check the impact without creating the subgraph
npx wgc subgraph check <name> --schema schema.graphql --label team=A

Description

The npx wgc subgraph check command checks for breaking changes and composition errors in all connected federated graphs associated with the specified subgraph. This validation process ensures that the new schema you intend to use does not introduce any issues that could negatively impact existing federated graphs.

This command also checks feature subgraphs. Pass its name to validate the proposed schema against the feature flag compositions that include it. See Schema Checks. Composition errors, composition warnings, and composed breaking changes include a FEATURE_FLAG column identifying the feature flag each entry belongs to (empty for the base supergraph).

Parameters

Options

The check command requires either the --schema or --delete parameter.

Examples

  1. Check for breaking changes and composition errors for the subgraph “products” with the new schema file located at ”./schemas/new_schema.graphql”:
npx wgc subgraph check products -n default --schema ./schemas/new_schema.graphql
  1. Check for breaking changes and composition errors for the subgraph which does not exist yet:
npx wgc subgraph check newSubgraph -n default --schema ./schemas/new_schema.graphql --label team=A
  1. Output the check result as JSON for automation:
npx wgc subgraph check products -n default --schema ./schemas/new_schema.graphql --json
  1. Write the JSON check result to a file:
npx wgc subgraph check products -n default --schema ./schemas/new_schema.graphql --out ./check-result.json

The labels should match the labels of the federated graph you want to check against.

Sample output with changes and errors

Changes

CHANGE TYPE DESCRIPTION BREAKING
BREAKING FIELD_REMOVED Field ‘email’ was removed from object type ‘User’
NON-BREAKING FIELD_ADDED Field ‘emailID’ was added to object type ‘User’

Composition Errors

FEDERATED_GRAPH_NAME ERROR_MESSAGE
inventory Type “Product” is an extension type, but there is no type definition for “Product” in any subgraphs.
  1. Check for breaking changes and composition errors for the subgraph “products” with the new schema file located at ”./schemas/new_schema.graphql”:
npx wgc subgraph check employees --delete

Sample output

Changes

CHANGE TYPE DESCRIPTION BREAKING
BREAKING TYPE_REMOVED Type ‘Department’ was removed
NON-BREAKING TYPE_REMOVED Type ‘RoleType’ was removed

Composition Errors

FEDERATED_GRAPH_NAME ERROR_MESSAGE
inventory The subgraph “products” could not be federated for the following reason:
The object type “Employee” defines the directive “@override(from: “employees)” on the following field: “notes”.
The required “from” argument of type “String!” must be provided with an existing subgraph name.
However, a subgraph by the name of “employees” does not exist.

VCS Context

If you want to associate custom information with the checks being performed, you can do so by setting the following environment variables:

export COSMO_VCS_AUTHOR=foo@bar.com
export COSMO_VCS_COMMIT=de233ddwqedqwe
export COSMO_VCS_BRANCH=main

Usage in CI and GitHub Integration

Checkout the tutorial here on how to use the subgraph check command in CI with GitHub.

Notes