Usage
Prerequisites
Before using the Cosmo Previews GitHub Action, ensure that the following prerequisites are met:Cosmo API Key
You must have a valid API key from WunderGraph Cosmo, which should be stored as a secret in your GitHub repository under
COSMO_API_KEY
.Configuration File
Create a
cosmo.yaml
file in the .github
directory of your repository. This file should define the configuration for your subgraphs and feature flags.Subgraphs on Wundergraph Cosmo
All subgraphs referenced in the cosmo.yaml file must be created and published on Wundergraph Cosmo. Ensure that these subgraphs are correctly configured.
GitHub Token
The GitHub token is automatically provided by GitHub Actions, but ensure it is correctly referenced.
Setup
To use this action in your repository:- Create a
.github/cosmo.yaml
file that defines the configuration for your feature subgraphs and feature flags.
- The paths to schema files should be relative to the root of your repository.
-
The
routing_url
can include the placeholder string ’${PR_NUMBER}’, which will be replaced with the actual PR number. This enables deployment of the subgraph to a unique URL for each pull request. - Feature flag labels must match the federated graph for which the preview is created.
- Ensure that the subgraphs mentioned in cosmo.yaml are a part of a federated graph.
Example Workflow
Action Parameters
-
config_path
: The path to yourcosmo.yaml
configuration file. -
create
: Set totrue
to create the feature flag and subgraphs. -
update
: Set totrue
to update the feature subgraphs. -
destroy
: Set totrue
to destroy the feature flag and subgraphs. -
cosmo_api_key
: Your Cosmo API key stored in GitHub secrets. -
github_token
: Your GitHub token, typically${{ secrets.GITHUB_TOKEN }}
.
Jobs
Create
Thecreate
job is triggered when a pull request is opened or reopened. It performs the following actions:
- Checks out the repository.
- Sets up Node.js using the version specified.
-
Installs the latest version of the
wgc
CLI tool. -
Creates feature subgraphs for all the GraphQL files modified in the pull request, provided that their corresponding subgraph configuration is specified in the
cosmo.yaml
file. -
Creates all the feature flags specified in the
cosmo.yaml
file.
Update
Theupdate
job is triggered when a pull request is synchronized. It performs the following actions:
- Checks out the repository.
- Sets up Node.js with the specified version.
-
Installs the latest version of the
wgc
CLI tool. -
Creates/ Updates the feature subgraphs for all the newly modified GraphQL files in the pull request, provided that their corresponding subgraph configuration is specified in the
cosmo.yaml
file. -
Updates all the feature flags specified in the
cosmo.yaml
file.
Destroy
Thedestroy
job is triggered when a pull request is closed. It performs the following actions:
- Checks out the repository.
- Sets up Node.js using the version specified.
-
Installs the latest version of the
wgc
CLI tool. - Destroys all the feature flags and feature subgraphs created for the pull request.
Outputs
-
feature_subgraphs_to_deploy
: A list of feature subgraphs to deploy. This output is provided in the create and update jobs. -
feature_subgraphs_to_destroy
: A list of feature subgraphs to destroy. This output is provided in the update and destroy jobs.
Limitations
- The cosmo.yaml file should not be changed after the pull request is opened. If changes are to be made, the pull request should be closed and reopened. Make sure that the destroy action is completed before reopening the pull request.