• Stars
    star
    265
  • Rank 153,432 (Top 4 %)
  • Language
    Ruby
  • License
    MIT License
  • Created about 7 years ago
  • Updated 11 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Get changes between two GraphQL schemas 🤖

GraphQL::SchemaComparator

Build status

GraphQL::SchemaComparator is a GraphQL Schema comparator. What does that mean? GraphQL::SchemaComparator takes two GraphQL schemas and outputs a list of changes between versions. This is useful for many things:

  • Breaking Change detection
  • Applying custom rules to schema changes
  • Building automated tools like linters

Installation

Add this line to your application's Gemfile:

gem 'graphql-schema_comparator'

And then execute:

$ bundle

Or install it yourself as:

$ gem install graphql-schema_comparator

CLI

GraphQL::SchemaComparator comes with a handy CLI to help compare two schemas using the command line.

After a gem install graphql-schema_comparator, use the CLI this way:

Commands:
  schema_comparator compare OLD_SCHEMA NEW_SCHEMA  # Compares OLD_SCHEMA with NEW_SCHEMA and returns a list of changes
  schema_comparator help [COMMAND]                 # Describe available commands or one specific command

Where OLD_SCHEMA and NEW_SCHEMA can be a string containing a schema IDL or a filename where that IDL is located.

Example

$ ./bin/schema_comparator compare "type Query { a: A } type A { a: String } enum B { A_VALUE }" "type Query { a: A } type A { b: String } enum B { A_VALUE ANOTHER_VALUE }"
⏳  Checking for changes...
🎉  Done! Result:

Detected the following changes between schemas:

🛑  Field `a` was removed from object type `A`
⚠️  Enum value `ANOTHER_VALUE` was added to enum `B`
✅  Field `b` was added to object type `A`

Usage

GraphQL::SchemaComparator, provides a simple api for Ruby applications to use.

Docs

http://www.rubydoc.info/github/xuorig/graphql-schema_comparator/master/GraphQL/SchemaComparator

GraphQL::SchemaComparator.compare

The compare method takes two arguments, old_schema and new_schema, the two schemas to compare.

You may provide schema IDL as strings, or provide instances of GraphQL::Schema.

The result of compare returns a SchemaComparator::Result object, from which you can access information on the changes between the two schemas.

  • result.breaking? returns true if any breaking changes were found between the two schemas
  • result.identical? returns true if the two schemas were identical
  • result.breaking_changes returns the list of breaking changes found between schemas.
  • result.non_breaking_changes returns the list of non-breaking changes found between schemas.
  • result.dangerous_changes returns the list of dangerous changes found between schemas.
  • result.changes returns the full list of change objects.

Change Objects

GraphQL::SchemaComparator returns a list of change objects. These change objects all inherit from Changes::AbstractChange

Possible changes are all found in changes.rb.

Change Criticality

Each change object has a #criticality method which returns a Changes::Criticality object. This objects defines how dangerous a change is to a schema.

The different levels of criticality (non_breaking, dangerous, breaking) are explained here: https://github.com/xuorig/graphql-schema_comparator/blob/master/lib/graphql/schema_comparator/changes/criticality.rb#L6-L19

The gem is available as open source under the terms of the MIT License.

More Repositories

1

anicca

Get a diff between two OpenAPI descriptions.
Rust
24
star
2

prg-pandoc-starter

A Minimal Pandoc Starter
CSS
19
star
3

graphql-active_record_batcher

GraphQL::ActiveRecordBatcher is a toolkit to batch record loading as well as preload ActiveRecord associations during GraphQL Execution.
Ruby
12
star
4

chromatophore

GraphQL Continuous Evolution
Kotlin
11
star
5

graphql-schema-design-workshop

11
star
6

graphql-persisted-documents-rails

A middleware for Rack applications allowing an endpoint to persist GraphQL documents
Ruby
9
star
7

react-native-strava-tss-calculator

Normalized Power, Variability Index, Training Stress Score Calculator
Objective-C
7
star
8

insyto

Insyto React / Relay App
JavaScript
4
star
9

graphql-ruby-generators

Generators to create GraphQL types from ActiveRecord models.
Ruby
4
star
10

graphql-cache-cdc-invalidation

Playing around with Debezium and invalidating a response cache
Kotlin
3
star
11

simple-rts

Working on a super simple RTS game using Bevy/Rust
Rust
2
star
12

ninety-nine-ocaml-problems

https://ocaml.org/learn/tutorials/99problems.html
OCaml
2
star
13

team-board

Shareable Web White Board
Ruby
2
star
14

grafakeql-client

Grafakeql
JavaScript
1
star
15

xuorig

Blog / Website built with GatsbyJS
JavaScript
1
star
16

prg-feedback

Feedback / corrections for http://book.productionreadygraphql.com/
1
star
17

agentify

Agent Thread as a Service 😇
Ruby
1
star
18

form-check-api

GraphQL API for form-check-app
Ruby
1
star
19

redocly-cli-lint-action

TypeScript
1
star
20

form-check-app

Form check for sports.
JavaScript
1
star
21

envoy-filter-playground

Playing with Custom Envoy Filters
C++
1
star
22

envoy-playground

Playin' around with Envoy as an edge proy
Ruby
1
star
23

rust-ws-chat

Playing with websockets in Rust
Rust
1
star
24

graphql-tools-ruby

GraphQL Executable Schema Builder & Other Tools
Ruby
1
star
25

code-notes

Some notes on code I read 👀
1
star
26

xuorig.github.io

My Personal Page
HTML
1
star