Skip to content

Commit

Permalink
Replace Apollo CLI with call to Apollo Studio API (#21)
Browse files Browse the repository at this point in the history
  • Loading branch information
iansu committed Dec 20, 2021
1 parent 4e3b247 commit 0e84ead
Show file tree
Hide file tree
Showing 28 changed files with 16,719 additions and 6,423 deletions.
2 changes: 2 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
build
coverage

jest.config.js
48 changes: 48 additions & 0 deletions .github/workflows/action-test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
name: Action Test

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

jobs:
local-test:
runs-on: ubuntu-latest
timeout-minutes: 20
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v2
if: ${{ !env.ACT }}
with:
node-version: 16
cache: npm
- uses: actions/setup-node@v2
if: ${{ env.ACT }}
with:
node-version: 16
- name: Install
run: npm install --prefer-offline
- name: Build
run: npm run build
- name: Upload schema
uses: ./
with:
title: Test API
graph: apollo-schema-check-action-test
variant: current
localSchemaFile: test/fixtures/test-schema.graphql
validationPeriod: P1M
apolloKey: ${{ secrets.APOLLO_KEY_TEST }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Upload federated schema
uses: ./
with:
title: Federated Test API
graph: apollo-schema-check-action-federated-test
variant: current
localSchemaFile: test/fixtures/test-schema.graphql
serviceName: test-service
validationPeriod: P1M
apolloKey: ${{ secrets.APOLLO_KEY_FEDERATED_TEST }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
12 changes: 6 additions & 6 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,16 @@ jobs:
- uses: actions/checkout@v2
- uses: actions/setup-node@v2
with:
node-version: 12
cache: yarn
node-version: 16
cache: npm
- name: Install
run: yarn --prefer-offline --frozen-lockfile --no-progress --non-interactive
run: npm install --prefer-offline
- name: Lint
run: yarn lint
run: npm run lint
- name: Build
run: yarn build
run: npm run build
- name: Test
run: yarn test --coverage
run: npm test --coverage
- name: Upload coverage
uses: codecov/codecov-action@v1
with:
Expand Down
2 changes: 1 addition & 1 deletion .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/bin/sh
. "$(dirname "$0")/_/husky.sh"

yarn lint-staged
npm run precommit
2 changes: 1 addition & 1 deletion .nvmrc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
12
16
2 changes: 1 addition & 1 deletion .prettierrc
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"printWidth": 100,
"printWidth": 120,
"singleQuote": true
}
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Apollo Schema Check Action Changelog

## 2.0.0 (December 20, 2021)

- Rewrite to not use the Apollo CLI

## 1.2.2 (December 2, 2021)

- Add additional debug logging
Expand Down
38 changes: 23 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ A GitHub Action to run a schema check using the [Apollo CLI](https://www.apollog

## Usage

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

```yml
name: Schema Check
Expand All @@ -24,7 +24,7 @@ jobs:
steps:
- uses: actions/checkout@v2
- name: Customer API check
uses: iansu/apollo-schema-check-action@v1
uses: iansu/apollo-schema-check-action@v2
with:
title: Customer API
graph: my-customer-api
Expand All @@ -41,22 +41,30 @@ When you create a new PR that includes schema changes the results of the schema
![Screenshot](./screenshot.png)
Note that you won't see a comment if your PR doesn't include any schema changes.
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

Almost all of the settings from the [Apollo CLI `schema:check` command](https://github.com/apollographql/apollo-tooling/tree/master/packages/apollo#apollo-servicecheck) are supported, with the following differences:

1. The `json` and `markdown` options have been removed because this action requires markdown to post a comment on your PR
1. The `header` option works slightly different, you pass it a comma separated list of headers. For example: `Header1=Value,Header2=Value2`.

Some additional settings have also been added:

| Name | Description | Default | Required |
| ------------- | ----------------------------------------------------------------------- | ------- | -------- |
| title | The name of the graph which will be shown in the comment | | No |
| alwaysComment | Leave a comment on the PR even if there are no schema changes in the PR | false | No |
| failOnError | Fail the check if breaking changes or composition errors are found | true | No |
If you provide the path to an [Apollo config file](https://www.apollographql.com/docs/devtools/apollo-config/) 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 `localSchemaFile`s.

| 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](https://en.wikipedia.org/wiki/ISO_8601#Durations) | | Yes |
| variant | The variant to check the proposed schema against | | No |

## Why use this instead of the Apollo GitHub App

Expand Down
16 changes: 6 additions & 10 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,17 @@ inputs:
endpoint:
description: The URL for the CLI to use to introspect your service
required: false
header:
description: 'Additional header to send to server for introspectionQuery. Multiple headers can be provided as a comma separated list. NOTE: The `--endpoint` flag is REQUIRED if using the `--header` flag.'
headers:
description: '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.'
required: false
key:
description: The API key to use for authentication to Apollo Graph Manager
required: false
required: true
localSchemaFile:
description: Path to one or more local GraphQL schema file(s), as introspection result or SDL. Supports comma-separated list of paths (ex. `--localSchemaFile=schema.graphql,extensions.graphql`)
description: Path to one or more local GraphQL SDL file(s). Supports comma-separated list of paths (ex. `schema.graphql,extensions.graphql`)
required: false
queryCountThreshold:
description: Minimum number of requests within the requested time window for a query to be considered.
description: Minimum number of requests within the requested time window for a query to be considered
required: false
queryCountThresholdPercentage:
description: 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)
Expand All @@ -47,13 +47,9 @@ inputs:
description: Fail the check if breaking changes or composition errors are found
default: 'true'
required: false
apolloVersion:
description: The version of the Apollo CLI to use
default: '2.33.9'
required: false

runs:
using: node12
using: node16
main: build/index.js

branding:
Expand Down
9 changes: 4 additions & 5 deletions jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,14 @@ module.exports = {
'!<rootDir>/node_modules/',
'!<rootDir>/build/',
'!<rootDir>/src/index.ts',
'!<rootDir>/*.js'
'!<rootDir>/*.js',
],
globals: {
'ts-jest': {
tsConfig: '<rootDir>/test/tsconfig.json',
packageJson: 'package.json'
}
tsconfig: '<rootDir>/test/tsconfig.json',
},
},
preset: 'ts-jest',
testEnvironment: 'node',
testPathIgnorePatterns: ['<rootDir>/build/']
testPathIgnorePatterns: ['<rootDir>/build/'],
};
Loading

0 comments on commit 0e84ead

Please sign in to comment.