Skip to content
check-square

GitHub Action

Apollo Schema Check Action

v2.1.0 Latest version

Apollo Schema Check Action

check-square

Apollo Schema Check Action

A GitHub Action to run a schema check and post the results as a comment on a Pull Request

Installation

Copy and paste the following snippet into your .yml file.

              

- name: Apollo Schema Check Action

uses: iansu/[email protected]

Learn more about this action in iansu/apollo-schema-check-action

Choose a version

Apollo Schema Check Action

Build status codecov

A GitHub Action to run a schema check using the Apollo CLI and Apollo Studio (formerly Graph Manager) and post the results as a comment on a Pull Request

Usage

Create a file in your repo named .github/workflows/schema-check.yml with the following contents:

name: Schema Check

on:
  pull_request:
    types: [opened, reopened, synchronize]

jobs:
  check_schema:
    name: check schema
    runs-on: ubuntu-latest
    timeout-minutes: 5
    steps:
      - uses: actions/checkout@v2
      - name: Customer API check
        uses: iansu/apollo-schema-check-action@v2
        with:
          title: Customer API
          graph: my-customer-api
          variant: production
          localSchemaFile: 'schema.graphql'
          serviceName: my-service
          validationPeriod: P2W
          key: ${{ secrets.APOLLO_KEY }}
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

When you create a new PR that includes schema changes the results of the schema check will be posted as a comment. Here's an example of what that looks like:

Screenshot

Note that you won't see a comment if your PR doesn't include any schema changes. You can change this behaviour by setting alwaysComment: true.

Settings

If you provide the path to an Apollo config file in your project any applicable settings from there will be used. If a setting is specified in the Apollo config file and in the workflow settings, the workflow setting will take precedence.

You must provide either an endpoint to introspect your schema or the path to one or more localSchemaFiles.

Name Description Default Required
alwaysComment Leave a comment on the PR even if there are no schema changes in the PR false No
config Path to your Apollo config file No
endpoint The URL for the CLI to use to introspect your service No
failOnError Fail the check if breaking changes or composition errors are found true No
graph The ID of the graph in Apollo Graph Manager to check your proposed schema changes against No
headers Additional headers to send to server for introspectionQuery. Multiple headers can be provided as a comma separated list. NOTE: The endpoint input is REQUIRED if using the headers input. No
key The API key to use for authentication to Apollo Graph Manager Yes
localSchemaFile Path to one or more local GraphQL SDL file(s). Supports comma-separated list of paths (ex. schema.graphql,extensions.graphql) No
queryCountThreshold Minimum number of requests within the requested time window for a query to be considered No
queryCountThresholdPercentage Number of requests within the requested time window for a query to be considered, relative to total request count. Expected values are between 0 and 0.05 (minimum 5% of total request volume) No
serviceName Provides the name of the implementing service for a federated graph. This flag will indicate that the schema is a partial schema from a federated service No
title The name of the graph which will be shown in the comment No
validationPeriod The size of the time window with which to validate the schema against. You may provide a number (in seconds), or an ISO8601 format duration for more granularity (see: ISO 8601 Durations Yes
variant The variant to check the proposed schema against No

Why use this instead of the Apollo GitHub App

This Action offers some features that the Apollo GitHub App doesn't. If you don't need these features then you should consider using it instead. The main differences are:

  1. You don't have to install an app in your org or repo to use this Action
  2. This Action posts a comment with the results directly on your PR
  3. This Action supports multiple graphs

Releasing

Publishing a release

To publish a release use the Release workflow. When you run the workflow it will ask you for a version tag like v2.0.0. This should be the full version number of the new release. It will also ask you for a major version number like v2. This allows you to reference the release as either @v2 of @v2.0.0. You can also reference the hash of the release for additional security.

After the workflow runs a draft release will be created on GitHub. Edit the release and copy the CHANGELOG entries into the description. Then publish the release, including publishing to the GitHub Marketplace.

Creating a preview Release

To create a preview release use the Release Next workflow. When you run the workflow it will ask you for the name of the branch to build. This should be the feature branch that you want to test. The release will be published to the next branch and you can use iansu/apollo-schema-check-action@next in your workflows to test the preview release.

Credits

Made with 🥃 by Ian Sutherland (@iansu). This project is released under the MIT license.