Skip to content

πŸ•΅οΈβ€β™€οΈ Tooling for GraphQL. Compare schemas, validate documents, find breaking changes, find similar types, schema coverage

License

Notifications You must be signed in to change notification settings

ChopperLee2011/graphql-inspector

Β 
Β 

Repository files navigation

GraphQL Inspector

CircleCI npm version code style: prettier renovate-app badge

GraphQL Inspector ouputs a list of changes between two GraphQL schemas. Every change is precisely explained and marked as breaking, non-breaking or dangerous. It helps you validate documents and fragments against a schema and even find similar or duplicated types.

Example

Features

Major features:

  • Compares schemas
  • Finds breaking or dangerous changes
  • Validates documents against a schema
  • Finds similar / duplicated types
  • Schema coverage based on documents
  • Serves a GraphQL server with faked data and GraphQL Playground

GraphQL Inspector has a CLI and also a programatic API, so you can use it however you want to and even build tools on top of it.

Installation

yarn add graphql-inspector

CLI Usage

graphql-inspector diff     <OLD_SCHEMA> <NEW_SCHEMA>
graphql-inspector validate <DOCUMENTS>  <SCHEMA>
graphql-inspector similar  <SCHEMA>
graphql-inspector serve    <SCHEMA>
graphql-inspector coverage <DOCUMENTS>  <SCHEMA>
graphql-inspector --help

Examples

# Compare schemas
$ graphql-inspector diff OLD_SCHEMA NEW_SCHEMA

Detected the following changes (4) between schemas:

πŸ›‘  Field `name` was removed from object type `Post`
⚠️  Enum value `ARCHIVED` was added to enum `Status`
βœ…  Field `createdAt` was added to object type `Post`

Detected 1 breaking change


# Validate documents
$ graphql-inspector validate DOCUMENTS SCHEMA

Detected 1 invalid document:

πŸ›‘  ./documents/post.graphql:
  - Cannot query field createdAtSomePoint on type Post. Did you mean createdAt?


# Find similar types
$ graphql-inspector similar SCHEMA

βœ… Post
Best match (60%): BlogPost


# Serve faked GraphQL API with Playground
$ graphql-inspector serve SCHEMA

βœ… Serving the GraphQL API on http://localhost:4000/


# Check coverage
$ graphql-inspector coverage DOCUMENTS SCHEMA

Schema coverage

type Query {
  post x 1
}

type Post {
  id x 1
  title x 1
  πŸ›‘ createdAt x 0
  πŸ›‘ modifiedAt x 0
}

Programatic Usage

import {
  diff,
  validate,
  similar,
  coverage,
  Change,
  InvalidDocument,
  SimilarMap,
  SchemaCoverage,
} from 'graphql-inspector';

// diff
const changes: Change[] = diff(schemaA, schemaB);
// validate
const invalid: InvalidDocument[] = validate(documentsGlob, schema);
// similar
const similar: SimilarMap = similar(schema, typename, threshold);
// coverage
const schemaCoverage: SchemaCoverage = coverage(schema, documents);
// ...

Related

Some part of the library was ported to NodeJS from Ruby's GraphQL Schema Comparator

License

MIT Β© Kamil Kisiela

About

πŸ•΅οΈβ€β™€οΈ Tooling for GraphQL. Compare schemas, validate documents, find breaking changes, find similar types, schema coverage

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • TypeScript 99.0%
  • JavaScript 1.0%