Skip to content

CI/CD Integration

The shortest path is the GitHub Action:

name: GraphQL
on: [pull_request]
jobs:
check:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: trevor-scheer/graphql-analyzer-action@v1

It installs the released CLI, runs graphql check, emits inline PR annotations, and supports SARIF + an optional summary comment. See the GitHub Action page for the full reference.

If you’d rather call the CLI directly — for example, on self-hosted runners or to share install logic across many steps — the binary install pattern still works:

name: GraphQL Validation
on: [pull_request]
jobs:
graphql:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Install GraphQL CLI
run: |
curl --proto '=https' --tlsv1.2 -LsSf \
https://raw.githubusercontent.com/trevor-scheer/graphql-analyzer/main/scripts/install.sh | sh
- name: Check GraphQL
run: graphql check --format github

--format github turns errors into pull request annotations.

- name: Check GraphQL (SARIF)
run: graphql check --format sarif > results.sarif
- name: Upload SARIF
uses: github/codeql-action/upload-sarif@v3
with:
sarif_file: results.sarif

To run validation and linting as separate steps:

- name: Validate GraphQL
run: graphql validate --format github
- name: Lint GraphQL
run: graphql lint --format github
graphql:
script:
- curl --proto '=https' --tlsv1.2 -LsSf https://raw.githubusercontent.com/trevor-scheer/graphql-analyzer/main/scripts/install.sh | sh
- graphql check --format json
Terminal window
# Install
curl -LsSf https://raw.githubusercontent.com/trevor-scheer/graphql-analyzer/main/scripts/install.sh | sh
# Run checks
graphql check --format json > results.json
# Check exit code
if [ $? -ne 0 ]; then
echo "GraphQL validation failed"
exit 1
fi

Using husky:

{
"husky": {
"hooks": {
"pre-commit": "graphql check"
}
}
}

Some lint rules (like noUnusedFields) are too expensive for real-time editor feedback but work well in CI. Enable them via CLI-specific config overrides in .graphqlrc.yaml:

extensions:
lint:
extends: recommended
cli:
lint:
rules:
noUnusedFields: error
noUnusedFragments: error

The extensions.cli.lint.rules block applies only when running the CLI, so the LSP and editor stays fast.

Use --max-warnings 0 to treat any warning as a failure:

Terminal window
graphql check --max-warnings 0

This returns exit code 6 if any warnings are found, making CI strict about warnings without promoting them all to errors in the config.