Coder Social home page Coder Social logo

graphql-schema_comparator's Introduction

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.

graphql-schema_comparator's People

Contributors

cjoudrey avatar danpalmer avatar eapache avatar eileencodes avatar gjtorikian avatar haruska avatar jturkel avatar lostie avatar rmosolgo avatar sambostock avatar stanboyet avatar swalkinshaw avatar themetalcode avatar xuorig avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.