### Install GraphQL Inspector GitHub Actions Source: https://github.com/graphql-hive/graphql-inspector/blob/master/packages/cli/README.md Installs the global CLI for GitHub Actions integration. ```bash pnpm add --global @graphql-inspector/actions ``` -------------------------------- ### Install GraphQL Inspector Core Source: https://github.com/graphql-hive/graphql-inspector/blob/master/packages/core/README.md Install the core package using pnpm. This is the first step to using the GraphQL Inspector. ```bash pnpm add @graphql-inspector/core ``` -------------------------------- ### Example Usage of Similar Command Source: https://github.com/graphql-hive/graphql-inspector/blob/master/website/src/pages/docs/commands/similar.mdx This example demonstrates how to use the similar command with a specific GraphQL schema file. It will output any found similar types. ```bash graphql-inspector similar example/schemas/deep.graphql ``` -------------------------------- ### Basic GitHub Action Setup Source: https://github.com/graphql-hive/graphql-inspector/blob/master/website/src/pages/docs/products/action.mdx This is a basic setup for the GitHub Action. It checks out the code and then uses the GraphQL Inspector action to compare the schema in the PR against the `master` branch. ```yaml name: CI on: [push] jobs: test: name: Check Schema runs-on: ubuntu-latest steps: - name: Checkout uses: actions/checkout@master - uses: graphql-hive/graphql-inspector@master with: schema: 'master:schema.graphql' ``` -------------------------------- ### Install GraphQL and Git Loaders Source: https://github.com/graphql-hive/graphql-inspector/blob/master/website/src/pages/docs/products/ci.mdx Installs packages required to load GraphQL schemas from local files and Git repositories, essential for schema comparison in CI. ```sh npm i --global @graphql-inspector/graphql-loader @graphql-inspector/git-loader ``` -------------------------------- ### Install GraphQL Inspector CLI Source: https://github.com/graphql-hive/graphql-inspector/blob/master/packages/cli/README.md Installs the GraphQL Inspector CLI package using pnpm. ```bash pnpm add @graphql-inspector/cli ``` -------------------------------- ### Use GraphQL Inspector GitHub Bot Source: https://github.com/graphql-hive/graphql-inspector/blob/master/packages/cli/README.md Example command to initiate the GitHub bot functionality. ```bash $ graphql-inspector-github ``` -------------------------------- ### Install GraphQL Inspector CLI Source: https://github.com/graphql-hive/graphql-inspector/blob/master/website/src/pages/docs/installation.mdx Install the global CLI tool for GraphQL Inspector. Includes `graphql` as a peer dependency. ```sh npm i --global @graphql-inspector/cli graphql ``` -------------------------------- ### Install GraphQL CLI Source: https://github.com/graphql-hive/graphql-inspector/blob/master/website/src/pages/docs/products/ci.mdx Installs the 'graphql' package globally, which may be a dependency for certain GraphQL Inspector operations. ```sh npm i --global graphql ``` -------------------------------- ### Introspection Example with Output Path Source: https://github.com/graphql-hive/graphql-inspector/blob/master/website/src/pages/docs/commands/introspect.mdx This example demonstrates how to use the `introspect` command to generate an introspection file from a local GraphQL schema file and specify the directory where the output should be saved. ```sh graphql-inspector introspect example/schemas/new-valid.graphql --write example/schemas ``` -------------------------------- ### Install GraphQL Inspector Core Package Source: https://github.com/graphql-hive/graphql-inspector/blob/master/website/src/pages/docs/installation.mdx Install the core package for using GraphQL Inspector programmatically. ```sh npm i @graphql-inspector/core ``` -------------------------------- ### Install GraphQL Inspector CI CLI Source: https://github.com/graphql-hive/graphql-inspector/blob/master/website/src/pages/docs/installation.mdx Install the global CLI tool specifically for CI environments. This version is optimized for size. ```sh npm i --global @graphql-inspector/ci ``` -------------------------------- ### Configure Basic Notifications Source: https://github.com/graphql-hive/graphql-inspector/blob/master/website/src/pages/docs/notifications.mdx Set up basic notifications by defining your Slack, Discord, or webhook URL. This is the simplest way to get started with schema change alerts. ```yaml notifications: slack: 'your-slack-webhook' discord: 'your-discord-webhook' webhook: 'your-own-webhook' ``` -------------------------------- ### Single Environment Configuration Source: https://github.com/graphql-hive/graphql-inspector/blob/master/website/src/pages/docs/recipes/environments.mdx Defines a basic setup with a single schema and branch. Use this for simple projects with only one environment. ```yaml schema: schema.graphql branch: master ``` -------------------------------- ### Example Schema Diff with Custom Directives Source: https://github.com/graphql-hive/graphql-inspector/blob/master/website/src/pages/docs/commands/diff.mdx Shows a before and after example of GraphQL schemas where a custom directive is added to a field, demonstrating how GraphQL Inspector tracks such changes. ```graphql directive @foo on INPUT_FIELD_DEFINITION input Foo { a: String @foo b: String } ``` -------------------------------- ### Example Introspection File Structure Source: https://github.com/graphql-hive/graphql-inspector/blob/master/website/src/pages/docs/commands/introspect.mdx This is an example of the JSON structure generated by the introspection command, representing a GraphQL schema. ```json { "__schema": { "description": null, "queryType": { "name": "Query" }, "mutationType": null, "subscriptionType": null, "types": [], "directives": [] } } ``` -------------------------------- ### Serve GraphQL Schema Command Source: https://github.com/graphql-hive/graphql-inspector/blob/master/website/src/pages/docs/commands/serve.mdx Use this command to start a GraphQL server with faked data based on your schema. Ensure the SCHEMA argument points to a valid schema file or URI. ```bash graphql-inspector serve SCHEMA ``` -------------------------------- ### Install GraphQL Inspector Diff Command Source: https://github.com/graphql-hive/graphql-inspector/blob/master/website/src/pages/docs/products/ci.mdx Installs the specific package for schema diffing, a common CI task. Use this when you only need the diff functionality. ```sh npm i --global @graphql-inspector/diff-command ``` -------------------------------- ### Compare Local Schema with Remote Server Source: https://github.com/graphql-hive/graphql-inspector/blob/master/website/src/pages/docs/commands/coverage.mdx This example demonstrates how to compare your local schema against a remote GraphQL server using the coverage command. Ensure the document and schema paths are correct. ```sh graphql-inspector coverage example/documents/post.graphql example/schemas/new-valid.graphql ``` -------------------------------- ### Serve Mocked GraphQL API Source: https://context7.com/graphql-hive/graphql-inspector/llms.txt Starts a local GraphQL server with faked data from a schema for development and testing. Can serve from local SDL files or JS module exports, and allows custom port configuration. ```bash graphql-inspector serve schema.graphql ``` ```bash graphql-inspector serve schema.graphql --port 5000 ``` ```bash graphql-inspector serve ./src/schema.js ``` -------------------------------- ### Run GraphQL Inspector with Docker Source: https://github.com/graphql-hive/graphql-inspector/blob/master/website/src/pages/docs/installation.mdx Execute GraphQL Inspector commands using a Docker container. This example shows how to display help. ```sh docker run kamilkisiela/graphql-inspector --help ``` -------------------------------- ### Single Environment Endpoint Setup Source: https://github.com/graphql-hive/graphql-inspector/blob/master/website/src/pages/docs/recipes/endpoints.mdx Configure a single GraphQL endpoint for schema introspection. Supports simple URLs or GET/POST requests with custom headers. ```yaml # POST with no headers endpoint: '' schema: schema.graphql # GET or POST with headers schema: schema.graphql endpoint: url: '' method: GET headers: auth: Basic ``` -------------------------------- ### Configure GraphQL Inspector in package.json Source: https://github.com/graphql-hive/graphql-inspector/blob/master/packages/cli/README.md Example configuration for GraphQL Inspector within a project's package.json, including schema introspection and diffing. ```json { "name": "app", "scripts": { "precommit": "graphql-inspector introspect schema.js --write schema.graphql && git add schema.graphql" }, "graphql-inspector": { "diff": true, "schema": { "ref": "master", "path": "schema.graphql" } } } ``` -------------------------------- ### GraphQL Inspector package.json Configuration Source: https://github.com/graphql-hive/graphql-inspector/blob/master/website/src/pages/docs/migration-guides/from-app-to-action.mdx Example of configuring GraphQL Inspector within the package.json file, specifying the branch and schema path. ```jsonc { // ... "graphql-inspector": { "branch": "master", "schema": "schema.graphql" } } ``` -------------------------------- ### Multiple Environment Endpoint Setup Source: https://github.com/graphql-hive/graphql-inspector/blob/master/website/src/pages/docs/recipes/endpoints.mdx Define multiple GraphQL endpoints for different environments like production and development. Each environment can have its own branch and endpoint configuration. ```yaml schema: schema.graphql env: production: branch: master endpoint: '' development: branch: develop endpoint: url: '' method: GET headers: auth: Basic ``` -------------------------------- ### Example Webhook Payload Source: https://github.com/graphql-hive/graphql-inspector/blob/master/website/src/pages/docs/notifications.mdx An example of the JSON payload structure received by a webhook, illustrating different types of schema changes. ```json { "environment": "production", "changes": [ { "message": "Field 'user' was removed from object type 'Query'", "level": "breaking" }, { "message": "Argument 'limit: Int' added to field 'Query.users'", "level": "dangerous" }, { "message": "Field 'role' added to object type 'User'", "level": "safe" } ] } ``` -------------------------------- ### GraphQL Inspector YAML Configuration Source: https://github.com/graphql-hive/graphql-inspector/blob/master/website/src/pages/docs/migration-guides/from-app-to-action.mdx Example of a YAML configuration file for GraphQL Inspector, specifying the branch and schema path. ```yaml branch: master schema: schema.graphql # an output of `$ graphql-inspector introspect ...` ``` -------------------------------- ### Interactive Docker Session Source: https://github.com/graphql-hive/graphql-inspector/blob/master/website/src/pages/docs/installation.mdx Start an interactive terminal session within the GraphQL Inspector Docker container. ```sh docker run -it kamilkisiela/graphql-inspector ``` -------------------------------- ### Docker Run with Volume Bind Source: https://github.com/graphql-hive/graphql-inspector/blob/master/website/src/pages/docs/installation.mdx Run GraphQL Inspector via Docker, binding the current directory to the container's `/app` for local file access. This example runs the `diff` command. ```sh docker run -v $PWD:/app kamilkisiela/graphql-inspector graphql-inspector diff old.graphql new.graphql ``` -------------------------------- ### CLI: Diff Schemas Source: https://context7.com/graphql-hive/graphql-inspector/llms.txt Compares two GraphQL schema sources from the command line and outputs categorized changes with color coding. Requires installation of the CLI package. ```bash # Install npm install -g @graphql-inspector/cli # Compare two local SDL files graphql-inspector diff schema-old.graphql schema-new.graphql ``` -------------------------------- ### Get Schema from Git Repository Source: https://github.com/graphql-hive/graphql-inspector/blob/master/website/src/pages/docs/api/schema.mdx Specify a schema file from a Git repository using the format 'git:branch:path/to/file'. ```bash git:origin/branch:path/to/file ``` ```bash git:origin/master:./schema.graphql ``` -------------------------------- ### Programmatic API for Loading Documents Source: https://github.com/graphql-hive/graphql-inspector/blob/master/website/src/pages/docs/api/documents.mdx Use the programmatic API with `@graphql-tools/load` to load documents from GraphQL files. This example demonstrates loading documents, converting them to the expected format, and validating them against a schema. ```javascript const { validate } = require('@graphql-inspector/core') const { loadDocuments } = require('@graphql-tools/load') const { GraphQLFileLoader } = require('@graphql-tools/graphql-file-loader') const graphql = require('graphql') const documents = loadDocuments('./src/**/*.graphql', { loaders: [new GraphQLFileLoader()] }) // Convert documents to the format expected by "validate" function const sources = documents.map(doc => { return new graphql.Source(graphql.print(doc.document), doc.location) }) const invalidDocuments = validate(schema, sources) ``` -------------------------------- ### Example of an Unreachable Type Source: https://github.com/graphql-hive/graphql-inspector/blob/master/website/src/pages/docs/commands/diff.mdx Demonstrates a GraphQL schema structure where a type is defined but not accessible from the root Query type, illustrating the concept of an unreachable type. ```graphql type Query { me: String } """ User can't be requested, it's unreachable """ type User { id: ID! } ``` -------------------------------- ### Get Schema from GitHub Repository Source: https://github.com/graphql-hive/graphql-inspector/blob/master/website/src/pages/docs/api/schema.mdx Fetch a GraphQL schema file from a GitHub repository using the format 'github:owner/name#ref:path/to/file'. A GitHub token may be required. ```bash github:owner/name#ref:path/to/file ``` ```bash github:kamilkisiela/graphql-inspector-example#master:./schema.graphql --token 'github-token-here' ``` -------------------------------- ### CircleCI Configuration for Schema Diff Source: https://github.com/graphql-hive/graphql-inspector/blob/master/website/src/pages/docs/products/ci.mdx Example CircleCI configuration to run the GraphQL Inspector schema diff command within a Docker container. It checks out the code and executes the diff. ```yaml version: 2 jobs: build: docker: - image: kamilkisiela/graphql-inspector steps: - checkout - run: name: GraphQL Inspector command: 'graphql-inspector diff "git:origin/master:./schema.graphql" "schema.graphql"' ``` -------------------------------- ### JavaScript Usage Check Script for `considerUsage` Source: https://github.com/graphql-hive/graphql-inspector/blob/master/website/src/pages/docs/commands/diff.mdx An example JavaScript file that implements the logic for the `--onUsage` flag. It checks if schema entities have been used in the last 30 days to decide if a change is breaking. ```javascript const BREAKING = false const NOT_BREAKING = true module.exports = entities => { return Promise.all( entities.map(async ({ type, field, argument }) => { // User => { type: 'User' } // Query.id => { type: 'Query', field: 'me' } // Query.users(last: 10) => { type: 'Query', field: 'users', argument: 'last' } const used = await checkIfUsedInLast30Days(type, field, argument) return used ? BREAKING : NOT_BREAKING }) ) } ``` -------------------------------- ### CLI Help Source: https://github.com/graphql-hive/graphql-inspector/blob/master/packages/cli/README.md Access help information for the main CLI commands and subcommands. ```bash graphql-inspector --help ``` ```bash graphql-inspector similar --help ``` -------------------------------- ### Advanced Environment Configuration with Overrides Source: https://github.com/graphql-hive/graphql-inspector/blob/master/website/src/pages/docs/recipes/environments.mdx Demonstrates advanced configuration where global settings are merged with environment-specific settings. Environment settings take precedence in case of conflicts, allowing for fine-grained control. ```yaml schema: schema.graphql diff: annotations: true notifications: webhook: '' slack: '' env: production: branch: master notifications: slack: '' preview: branch: develop diff: annotations: false ``` -------------------------------- ### GraphQL Inspector CLI Help Source: https://github.com/graphql-hive/graphql-inspector/blob/master/website/src/pages/docs/installation.mdx Display help information for the GraphQL Inspector CLI. ```sh graphql-inspector --help ``` -------------------------------- ### Check Schema Coverage using CLI Source: https://github.com/graphql-hive/graphql-inspector/blob/master/packages/cli/README.md Calculates schema coverage based on provided documents using the CLI. ```bash $ graphql-inspector coverage DOCUMENTS SCHEMA ``` -------------------------------- ### Defining a Custom Directive Source: https://github.com/graphql-hive/graphql-inspector/blob/master/website/src/pages/docs/commands/diff.mdx Example of defining a custom directive in a GraphQL schema. Directives can be applied to various schema elements. ```graphql directive @customDirective on FIELD_DEFINITION ``` -------------------------------- ### Environment-Specific Notifications Source: https://github.com/graphql-hive/graphql-inspector/blob/master/website/src/pages/docs/notifications.mdx Customize notifications per environment. For example, send all webhook notifications but only Slack notifications for the production environment. ```yaml notifications: webhook: 'your-own-webhook' env: production: branch: 'master' notifications: slack: '' dev: branch: 'develop' ``` -------------------------------- ### Creating and Using a Custom Rule (JavaScript) Source: https://github.com/graphql-hive/graphql-inspector/blob/master/website/src/pages/docs/commands/diff.mdx Demonstrates how to create a custom rule in JavaScript by filtering changes and then applying this custom rule using the `--rule` flag. ```javascript module.exports = ({ changes }) => { return changes.filter(myCustomFilter) } ``` -------------------------------- ### Serve Faked GraphQL API using CLI Source: https://github.com/graphql-hive/graphql-inspector/blob/master/packages/cli/README.md Serves a GraphQL API with faked data and GraphQL Playground using the CLI. ```bash $ graphql-inspector serve SCHEMA ``` -------------------------------- ### Disable Annotations in Single Environment Source: https://github.com/graphql-hive/graphql-inspector/blob/master/website/src/pages/docs/recipes/annotations.mdx To disable annotations for a single environment setup, set 'annotations' to 'false' within the 'diff' configuration. ```yaml diff: annotations: false ``` -------------------------------- ### Apply Schema Changes with Patch Source: https://github.com/graphql-hive/graphql-inspector/blob/master/packages/patch/README.md Use this snippet to apply a list of changes to a GraphQL schema. Ensure you have `@graphql-inspector/core` and `@graphql-inspector/patch` installed and imported. ```typescript import { buildSchema } from "graphql"; import { diff } from "@graphql-inspector/core"; import { patchSchema } from "@graphql-inspector/patch"; const schemaA = buildSchema(before, { assumeValid: true, assumeValidSDL: true }); const schemaB = buildSchema(after, { assumeValid: true, assumeValidSDL: true }); const changes = await diff(schemaA, schemaB); const patched = patchSchema(schemaA, changes); ``` -------------------------------- ### Compare GraphQL Schemas from Files Source: https://github.com/graphql-hive/graphql-inspector/blob/master/website/src/pages/docs/api/schema.mdx Compare two GraphQL schema files using their file paths. Supports extensions like .graphql, .graphqls, and .gql. ```bash graphql-inspector diff ./old-schema.graphql ./new-schema.gql ``` -------------------------------- ### Run Similar Command Source: https://github.com/graphql-hive/graphql-inspector/blob/master/website/src/pages/docs/commands/similar.mdx Execute the similar command with a schema file to find duplicate types. The SCHEMA argument points to your GraphQL schema file. ```bash graphql-inspector similar SCHEMA ``` -------------------------------- ### Multiple Environments Configuration Source: https://github.com/graphql-hive/graphql-inspector/blob/master/website/src/pages/docs/recipes/environments.mdx Adds multiple environments (e.g., production, preview) by defining their respective branches. This enables targeted features for each environment. ```yaml schema: schema.graphql env: production: branch: master preview: branch: develop ``` -------------------------------- ### Perform Schema Diff in CI Source: https://github.com/graphql-hive/graphql-inspector/blob/master/website/src/pages/docs/products/ci.mdx Compares a local schema file against a schema from a Git branch using the installed CLI and loaders. This is a typical CI check. ```sh graphql-inspector diff 'git:origin/master:./schema.graphql' 'schema.graphql' ``` -------------------------------- ### Load Schema from GraphQL or JSON File Source: https://github.com/graphql-hive/graphql-inspector/blob/master/packages/cli/README.md Directly use GraphQL schema files (`.graphql`, `.gql`) or introspection result JSON files (`.json`) with the `coverage` command. ```bash graphql-inspector coverage schema.graphql ``` ```bash graphql-inspector coverage schema.gql ``` ```bash graphql-inspector coverage introspected-schema.json ``` -------------------------------- ### Validate Documents with Schema and File Glob Source: https://github.com/graphql-hive/graphql-inspector/blob/master/website/src/pages/docs/commands/validate.mdx Example of validating GraphQL documents from a local file glob against a remote schema endpoint. Ensure documents are quoted. ```sh graphql-inspector validate './documents/*.graphql' http://localhost:3000/graphql ``` -------------------------------- ### Applying a Custom Rule (JavaScript) Source: https://github.com/graphql-hive/graphql-inspector/blob/master/website/src/pages/docs/commands/diff.mdx Shows the command-line usage for applying a custom JavaScript rule file to the schema diff process. ```bash graphql-inspector diff https://api.com/graphql schema.graphql --rule './custom-rule.js' ``` -------------------------------- ### GraphQL Inspector GitHub Action Job Source: https://github.com/graphql-hive/graphql-inspector/blob/master/website/src/pages/docs/migration-guides/from-app-to-action.mdx A GitHub Actions job that checks the GraphQL schema using the graphql-hive/graphql-inspector action. It checks out code, installs dependencies, and runs the inspector. ```yaml jobs: check-schema: name: Check GraphQL Schema runs-on: ubuntu-latest steps: - name: Checkout Code uses: actions/checkout@v2 - name: Install Dependencies run: npm install - name: Run GraphQL Inspector uses: graphql-hive/graphql-inspector@v2 with: schema: schema.graphql # Additional action inputs as needed ``` -------------------------------- ### Load Schema from GitHub Repository Source: https://github.com/graphql-hive/graphql-inspector/blob/master/packages/cli/README.md Reference a schema file in a GitHub repository using the `github:owner/name#ref:path/to/file` pattern. ```bash graphql-inspector coverage github:kamilkisiela/graphql-inspector-example#master:schema.graphql ``` -------------------------------- ### GraphQL Inspector CLI: Schema Diff Formats Source: https://context7.com/graphql-hive/graphql-inspector/llms.txt Demonstrates various ways to specify schema sources for the `graphql-inspector diff` command, including local files, JSON introspection, modules, live endpoints, and Git/GitHub references. ```bash # --- SCHEMA formats --- # Local SDL file graphql-inspector diff old.graphql new.graphql # Local JSON (introspection result) graphql-inspector diff old.json new.json # CommonJS / ESM module exporting GraphQLSchema, SDL string, or IntrospectionQuery graphql-inspector coverage ./src/**/*.graphql ./src/schema.js graphql-inspector coverage ./src/**/*.graphql ./src/schema.ts --require ts-node/register # Live HTTP endpoint graphql-inspector validate ./src/**/*.graphql https://api.example.com/graphql # Git reference — pattern: git:ref:path/to/file graphql-inspector diff git:origin/main:schema.graphql schema.graphql # GitHub repository — pattern: github:owner/repo#ref:path/to/file graphql-inspector diff \ github:myorg/myrepo#main:schema.graphql \ github:myorg/myrepo#feature-branch:schema.graphql ``` -------------------------------- ### Load Schema from URL Source: https://github.com/graphql-hive/graphql-inspector/blob/master/packages/cli/README.md Provide a URL to a GraphQL endpoint to fetch the schema directly using the `coverage` command. ```bash graphql-inspector coverage https://localhost:3000/graphql ``` -------------------------------- ### Applying a Custom Rule (TypeScript) Source: https://github.com/graphql-hive/graphql-inspector/blob/master/website/src/pages/docs/commands/diff.mdx Demonstrates the command-line usage for applying a custom TypeScript rule file to the schema diff. ```bash graphql-inspector diff https://api.com/graphql schema.graphql --rule './custom-rule.ts' ``` -------------------------------- ### Compare GraphQL Changes for Equality Source: https://github.com/graphql-hive/graphql-inspector/blob/master/packages/compare-changes/README.md Import necessary functions from @graphql-inspector/core and @graphql-inspector/compare-changes. Use `diff` to get changes between two schemas and `isChangeEqual` to check if a change is equivalent to an existing one. ```typescript import { buildSchema, } from 'graphql'; import { diff, } from '@graphql-inspector/diff'; import { isChangeEqual, } from '@graphql-inspector/compare-changes'; const before = buildSchema(/* existing SDL */); const after = buildSchema(/* new SDL */); const changes = diff(before, after); const hasChange = changes.some((c) => isChangeEqual(c, existingChange)); ``` -------------------------------- ### GraphQL Schema Example for Deprecated Field Removal Source: https://github.com/graphql-hive/graphql-inspector/blob/master/website/src/pages/docs/commands/diff.mdx These GraphQL schema snippets illustrate the effect of the `suppressRemovalOfDeprecatedField` rule. The first schema includes a deprecated field 'age', while the second schema removes it. ```graphql type User { id: ID name: String age: Int @deprecated } ``` ```graphql type User { id: ID name: String } ``` -------------------------------- ### Introspect GraphQL Server using CLI Source: https://github.com/graphql-hive/graphql-inspector/blob/master/packages/cli/README.md Introspects a GraphQL server and saves the schema definition to a JSON file using the CLI. ```bash $ graphql-inspector introspect SCHEMA --write schema.json ``` -------------------------------- ### Custom Interceptor Logic for Schema Changes Source: https://github.com/graphql-hive/graphql-inspector/blob/master/website/src/pages/docs/recipes/intercept.mdx Implement custom logic in a Node.js function to process schema changes. This example sets all change criticalities to 'NON_BREAKING' and the GitHub Check conclusion to 'success'. ```javascript module.exports = (req, res) => { const { changes } = req.body res.json({ changes: changes.map(change => ({ ...change, criticality: { ...change.criticality, level: 'NON_BREAKING' } })), conclusion: 'success' }) } ``` -------------------------------- ### Basic Coverage Command Source: https://github.com/graphql-hive/graphql-inspector/blob/master/website/src/pages/docs/commands/coverage.mdx Use this command to generate schema coverage statistics. Provide the path to your GraphQL documents and schema. ```sh graphql-inspector coverage DOCUMENTS SCHEMA ``` -------------------------------- ### Configure Husky for Schema Sync Source: https://github.com/graphql-hive/graphql-inspector/blob/master/website/src/pages/docs/products/ci.mdx Sets up a pre-commit hook using Husky to automatically dump the schema to a file before committing, ensuring consistency. ```jsonc { // ... "scripts": { "graphql:dump": "graphql-inspector introspect schema.js --write schema.graphql" }, "husky": { "hooks": { "pre-commit": "pnpm graphql:dump && git add schema.graphql" } } } ``` -------------------------------- ### Audit Documents using CLI (Basic) Source: https://github.com/graphql-hive/graphql-inspector/blob/master/packages/cli/README.md Audits GraphQL documents using the CLI to gather metrics like query depth, alias count, and directive count. ```bash $ pnpm graphql-inspector audit "packages/**/*.graphql|packages/**/*.ts(x)" ``` -------------------------------- ### Global Notifications Configuration Source: https://github.com/graphql-hive/graphql-inspector/blob/master/website/src/pages/docs/recipes/environments.mdx Sets up global notifications (e.g., Slack) that apply to all environments. This avoids repetitive configuration for common notification channels. ```yaml schema: schema.graphql notifications: slack: '' env: production: branch: master preview: branch: develop ``` -------------------------------- ### Load Schema from Local File Source: https://github.com/graphql-hive/graphql-inspector/blob/master/packages/cli/README.md Use the `coverage` command with a path to a CommonJS or ES Module exporting a schema object. For TypeScript files, use `--require ts-node/register`. ```bash graphql-inspector coverage ./src/schema.js ``` ```bash graphql-inspector coverage ./src/schema.ts --require ts-node/register ``` -------------------------------- ### Audit Documents using CLI (Detailed) Source: https://github.com/graphql-hive/graphql-inspector/blob/master/packages/cli/README.md Provides a detailed audit of GraphQL documents via the CLI, including operation-specific metrics for depth, aliases, and directives. ```bash $ pnpm graphql-inspector audit "packages/**/*.graphql|packages/**/*.ts(x)" --detail ``` -------------------------------- ### Load Schema from Git Repository Source: https://github.com/graphql-hive/graphql-inspector/blob/master/packages/cli/README.md Specify a schema file within a Git repository using the `git:ref:path/to/file` pattern for diffing. ```bash graphql-inspector diff git:origin/master:schema.graphql ``` -------------------------------- ### Compare Schemas using CLI Source: https://github.com/graphql-hive/graphql-inspector/blob/master/packages/cli/README.md Compares two GraphQL schemas using the CLI to identify changes. ```bash $ graphql-inspector diff OLD_SCHEMA NEW_SCHEMA ``` -------------------------------- ### Compare GraphQL Schemas from Endpoint Source: https://github.com/graphql-hive/graphql-inspector/blob/master/website/src/pages/docs/api/schema.mdx Compare a local schema file with a schema obtained by introspecting a GraphQL endpoint. ```bash graphql-inspector diff http://api.com/graphql ./new-schema.json ``` -------------------------------- ### GraphQL Inspector CLI: Document Source Formats Source: https://context7.com/graphql-hive/graphql-inspector/llms.txt Illustrates how to specify document sources for the `graphql-inspector validate` command using glob patterns for GraphQL files, TypeScript/JavaScript files (for gql template literals), and mixed globs. ```bash # --- DOCUMENTS (glob) formats --- # GraphQL files graphql-inspector validate './src/**/*.{graphql,gql,graphqls}' schema.graphql # TypeScript / JavaScript files (gql template literal extraction) graphql-inspector validate './src/**/*.{ts,tsx,js,jsx}' schema.graphql # Mixed glob graphql-inspector validate './src/**/*.graphql|./src/**/*.tsx' schema.graphql ``` -------------------------------- ### Basic Introspection Command Source: https://github.com/graphql-hive/graphql-inspector/blob/master/website/src/pages/docs/commands/introspect.mdx Use this command to dump an introspection file from a schema. It supports `.graphql`, `.gql`, and `.json` extensions for the schema file. The output is written to the specified path. ```sh graphql-inspector introspect SCHEMA --write path/to/file ``` -------------------------------- ### Using `onUsage` with `considerUsage` Rule Source: https://github.com/graphql-hive/graphql-inspector/blob/master/website/src/pages/docs/products/action.mdx When using the `considerUsage` rule, you must also provide a JavaScript file path to the `onUsage` input. This file should contain the custom logic for how usage is checked. ```yaml - uses: graphql-hive/graphql-inspector@master with: schema: 'master:schema.graphql' rules: | considerUsage onUsage: check-usage.js ``` -------------------------------- ### Compare GraphQL Schemas Source: https://context7.com/graphql-hive/graphql-inspector/llms.txt Compares GraphQL schemas from various sources including live endpoints, Git references, GitHub repositories, and local files. Supports rule-based suppression of changes and can fail on breaking changes. ```bash graphql-inspector diff schema.graphql https://api.example.com/graphql ``` ```bash graphql-inspector diff git:origin/main:schema.graphql schema.graphql ``` ```bash graphql-inspector diff \ github:myorg/myrepo#main:schema.graphql \ schema.graphql ``` ```bash graphql-inspector diff schema-old.js schema-new.ts --require ts-node/register ``` ```bash graphql-inspector diff old.graphql new.graphql \ --rule suppressRemovalOfDeprecatedField \ --rule ignoreDescriptionChanges ``` ```bash graphql-inspector diff old.graphql new.graphql --fail-on-breaking ``` -------------------------------- ### Load and Merge GraphQL Files in JavaScript Source: https://github.com/graphql-hive/graphql-inspector/blob/master/website/src/pages/docs/api/schema.mdx Use `@graphql-tools/load-files` to load multiple .graphql files and `@graphql-tools/schema` to create an executable schema. Supports CommonJS module system. ```javascript const { makeExecutableSchema } = require('@graphql-tools/schema') const { loadFilesSync } = require('@graphql-tools/load-files') const typeDefs = loadFilesSync('**/*.graphql') module.exports = makeExecutableSchema({ typeDefs }) ``` -------------------------------- ### Find Similar Fields in GraphQL Schemas Source: https://github.com/graphql-hive/graphql-inspector/blob/master/website/src/pages/docs/migration-guides/from-graphql-cli.mdx Compare how to find similar fields between two GraphQL schema files using GraphQL-CLI versus GraphQL-Inspector. The command syntax is identical. ```sh graphql similar schema.graphql schema2.graphql ``` ```sh graphql-inspector similar schema.graphql schema2.graphql ``` -------------------------------- ### Creating a Custom Rule (TypeScript) Source: https://github.com/graphql-hive/graphql-inspector/blob/master/website/src/pages/docs/commands/diff.mdx Illustrates how to define a custom rule using TypeScript, leveraging type safety for the `changes` object. ```typescript import type { Rule } from '@graphql-inspector/core' const rule: Rule = ({ changes }) => { return changes.filter(myCustomFilter) } export default rule ``` -------------------------------- ### Compare GraphQL Schemas from JSON Files Source: https://github.com/graphql-hive/graphql-inspector/blob/master/website/src/pages/docs/api/schema.mdx Compare two GraphQL schemas provided as JSON files containing introspection results. ```bash graphql-inspector diff ./old-schema.json ./new-schema.json ``` -------------------------------- ### Introspect GraphQL Server Source: https://context7.com/graphql-hive/graphql-inspector/llms.txt Introspects a live GraphQL server and saves the schema definition to a file in JSON or SDL format. Supports custom HTTP headers for authentication. ```bash graphql-inspector introspect https://api.example.com/graphql --write schema.json ``` ```bash graphql-inspector introspect https://api.example.com/graphql --write schema.graphql ``` ```bash graphql-inspector introspect https://api.example.com/graphql \ --header "Authorization: Bearer TOKEN" \ --write schema.json ``` -------------------------------- ### Multiple Environments Configuration Source: https://github.com/graphql-hive/graphql-inspector/blob/master/website/src/pages/docs/recipes/pull-requests.mdx Configure GraphQL Inspector for multiple environments, disabling `failOnBreaking` to prevent PR rejections for non-breaking changes across different branches. ```yaml diff: annotations: true schema: schema.graphql env: production: branch: master preview: branch: develop others: diff: failOnBreaking: false ``` -------------------------------- ### graphql-inspector diff (CLI) Source: https://context7.com/graphql-hive/graphql-inspector/llms.txt Compares two schema sources directly from the command line, outputting categorized changes with color coding for easy readability. ```APIDOC ## CLI — `graphql-inspector diff` ### Description Compares two schema sources from the command line and prints categorized changes with color coding. ### Usage ```bash # Install npm install -g @graphql-inspector/cli # Compare two local SDL files graphql-inspector diff schema-old.graphql schema-new.graphql ``` ### Parameters - **schema-old.graphql**: Path to the old schema file. - **schema-new.graphql**: Path to the new schema file. ``` -------------------------------- ### Applying Custom Rules with GitHub Action Source: https://github.com/graphql-hive/graphql-inspector/blob/master/website/src/pages/docs/products/action.mdx Extend the GraphQL Inspector's analysis by providing custom rules. These rules can be built-in rules or your own custom rule files. The `rules` input accepts a multi-line string listing the rules to apply. ```yaml - uses: graphql-hive/graphql-inspector@master with: schema: 'master:schema.graphql' rules: | suppressRemovalOfDeprecatedField custom-rule.js ``` -------------------------------- ### Multiple Environment Intercept Configuration Source: https://github.com/graphql-hive/graphql-inspector/blob/master/website/src/pages/docs/recipes/intercept.mdx Set up interceptors for different environments, specifying unique URLs and headers for each branch. This allows for environment-specific validation logic. ```yaml schema: schema.graphql # Or globally # intercept: env: production: branch: master intercept: '' development: branch: develop intercept: url: '' headers: auth: Basic ``` -------------------------------- ### Calculate GraphQL Schema Coverage Source: https://github.com/graphql-hive/graphql-inspector/blob/master/website/src/pages/docs/migration-guides/from-graphql-cli.mdx Compare how to calculate schema coverage based on GraphQL queries using GraphQL-CLI versus GraphQL-Inspector. Note the slight difference in quoting for the --queries argument. ```sh graphql coverage schema.graphql --queries="queries/**/*.graphql" ``` ```sh graphql-inspector coverage schema.graphql --queries "queries/**/*.graphql" ``` -------------------------------- ### Single Environment Configuration Source: https://github.com/graphql-hive/graphql-inspector/blob/master/website/src/pages/docs/recipes/pull-requests.mdx Configure GraphQL Inspector for a single environment, disabling `failOnBreaking` to prevent PR rejections for non-breaking changes. ```yaml diff: annotations: true schema: schema.graphql branch: master' others: diff: failOnBreaking: false ``` -------------------------------- ### Glob Pattern for GraphQL Files Source: https://github.com/graphql-hive/graphql-inspector/blob/master/website/src/pages/docs/api/documents.mdx Use glob patterns to specify GraphQL files. Inspector will extract operations and fragments. Supported extensions include `.graphql`, `.graphqls`, and `.gql`. Remember to wrap the glob pattern in quotes. ```bash ./src/app/**/*.graphql ``` -------------------------------- ### Diff GraphQL Schemas Source: https://github.com/graphql-hive/graphql-inspector/blob/master/website/src/pages/docs/migration-guides/from-graphql-cli.mdx Compare two GraphQL schema files using GraphQL-CLI versus GraphQL-Inspector. The command syntax is identical for this operation. ```sh graphql diff schema.graphql schema2.graphql ``` ```sh graphql-inspector diff schema.graphql schema2.graphql ``` -------------------------------- ### Using Multiple Named GraphQL Inspector Actions Source: https://github.com/graphql-hive/graphql-inspector/blob/master/website/src/pages/docs/products/action.mdx Configure multiple instances of the GraphQL Inspector action within the same workflow. Use the `name` input to differentiate them, preventing GitHub from overwriting results when checking different APIs (e.g., public vs. internal). ```yaml - uses: graphql-hive/graphql-inspector@master with: name: Validate Public API schema: 'master:public.graphql' - uses: graphql-hive/graphql-inspector@master with: name: Check Internal API schema: 'master:internal.graphql' ``` -------------------------------- ### Programmatic API Usage Source: https://github.com/graphql-hive/graphql-inspector/blob/master/website/src/pages/docs/installation.mdx Import core functionalities like diff, validate, and coverage from the GraphQL Inspector core package. ```ts import { diff, validate, coverage, ... } from '@graphql-inspector/core' ``` -------------------------------- ### Using the `considerUsage` Rule with a Usage Check Script Source: https://github.com/graphql-hive/graphql-inspector/blob/master/website/src/pages/docs/commands/diff.mdx This command diffs schemas and uses a provided JavaScript file to determine if a breaking change is truly breaking based on actual schema usage. ```bash graphql-inspector diff https://api.com/graphql schema.graphql --rule considerUsage --onUsage check-usage.js ``` -------------------------------- ### Schema Export Formats Source: https://github.com/graphql-hive/graphql-inspector/blob/master/packages/cli/README.md The CLI accepts schemas exported as strings, `GraphQLSchema` objects, GraphQL documents, or introspection query results. ```typescript // String export default ` type Query { hello: String } ` ``` ```typescript // GraphQLSchema export default makeExecutableSchema({...}); ``` ```typescript // GraphQL Document export default gql` type Query { hello: String } ` ``` ```typescript // IntrospectionQuery result export default { data: { __schema: { ... } } } ``` -------------------------------- ### Introspect GraphQL Schema Source: https://github.com/graphql-hive/graphql-inspector/blob/master/website/src/pages/docs/migration-guides/from-graphql-cli.mdx Compare how to introspect a GraphQL schema using GraphQL-CLI versus GraphQL-Inspector. Note the different syntax for providing headers. ```sh graphql get-schema --endpoint=https://api.example.com/graphql --header="Authorization: Bearer YOUR_TOKEN" > schema.graphql ``` ```sh graphql-inspector introspect https://api.example.com/graphql --headers '{"Authorization": "Bearer YOUR_TOKEN"}' > schema.graphql ``` -------------------------------- ### Similar Command - No Similar Types Found Source: https://github.com/graphql-hive/graphql-inspector/blob/master/website/src/pages/docs/commands/similar.mdx When no similar types are detected in the schema, the command outputs an informational message indicating that no similar types were found. ```bash info No similar types found ``` -------------------------------- ### Find Similar Types using CLI Source: https://github.com/graphql-hive/graphql-inspector/blob/master/packages/cli/README.md Finds similar or duplicated types within a GraphQL schema using the CLI. ```bash $ graphql-inspector similar SCHEMA ``` -------------------------------- ### Find Common Fields in GraphQL Schemas Source: https://github.com/graphql-hive/graphql-inspector/blob/master/website/src/pages/docs/migration-guides/from-graphql-cli.mdx Compare how to find common fields between two GraphQL schema files using GraphQL-CLI versus GraphQL-Inspector. The command syntax is identical. ```sh graphql common schema.graphql schema2.graphql ``` ```sh graphql-inspector common schema.graphql schema2.graphql ```