Skip to main content

Compare GraphQL Schemas

Project description

schemadiff

Compare GraphQL Schemas

Installation

$ pip install graphql-schema-diff

Usage

You can use this package as a lib or as a cli. You can choose what better suits your needs

Lib

>>> from schemadiff import diff, diff_from_file, format_diff
>>> old_schema = """
schema {
    query: Query
} 

type Query {
    a: Int!,
    sum(start: Float=0): Int
}
"""
>>> new_schema = """
schema {
    query: Query
} 

type Query {
    b: String,
    sum(start: Float=1): Int
}
"""
>>> changes = diff(old_schema, new_schema)
>>> print(format_diff(changes))                   # Pretty print difference
>>> any(change.breaking or change.dangerous for change in changes)    # Check if there was any breaking or dangerous change

# You can also compare from schema files
>>> with open('old_schema.gql', 'w') as f:
...     f.write(old_schema)
>>> with open('new_schema.gql', 'w') as f:
...     f.write(new_schema)
>>> changes = diff_from_file('old_schema.gql', 'new_schema.gql')
>>> print(format_diff(changes))

CLI

Inside your virtualenv you can invoke the entrypoint to see its usage options

$ schemadiff -h
Usage: schemadiff [-h] -o OLD_SCHEMA -n NEW_SCHEMA [-t] [-s]

Schema comparator

optional arguments:
  -h, --help            show this help message and exit
  -o OLD_SCHEMA, --old-schema OLD_SCHEMA
                        Path to old graphql schema file
  -n NEW_SCHEMA, --new-schema NEW_SCHEMA
                        Path to new graphql schema file
  -t, --tolerant        Tolerant mode. Error out only if there's a breaking
                        change but allow dangerous changes
  -s, --strict          Strict mode. Error out on dangerous and breaking
                        changes.

Examples

$ schemadiff -o tests/data/simple_schema.gql -n tests/data/new_schema.gql

$ schemadiff --old-schema tests/data/simple_schema.gql -n tests/data/new_schema.gql --tolerant

$ schemadiff -o tests/data/simple_schema.gql --new-schema tests/data/new_schema.gql --strict

Sample output

✅ Field `c` was added to object type `Query`
❌ Field `a` was removed from object type `Query`
🚸 Default value for argument `x` on field `Field.calculus` changed from `0` to `1`

Credits

Implementation was heavily inspired by Marc Giroux ruby version and Kamil Kisiela js implementation.

Contributions

Bug reports, Feature requests or pull request are welcome!

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

graphql-schema-diff-0.0.3.tar.gz (25.5 kB view details)

Uploaded Source

Built Distribution

graphql_schema_diff-0.0.3-py3-none-any.whl (44.2 kB view details)

Uploaded Python 3

File details

Details for the file graphql-schema-diff-0.0.3.tar.gz.

File metadata

  • Download URL: graphql-schema-diff-0.0.3.tar.gz
  • Upload date:
  • Size: 25.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/42.0.2 requests-toolbelt/0.9.1 tqdm/4.41.0 CPython/3.6.10

File hashes

Hashes for graphql-schema-diff-0.0.3.tar.gz
Algorithm Hash digest
SHA256 749d33037ce0d0dc4640af89870d368e0858bd250920b7897b97db2fea697e03
MD5 cc6b050a2d4be5e6ac629bcfc8eb4ffb
BLAKE2b-256 561cf3acec36bfd8c404e07cd0fbbff630ab2bd2b63ee88d666f6ca9c00165c9

See more details on using hashes here.

File details

Details for the file graphql_schema_diff-0.0.3-py3-none-any.whl.

File metadata

  • Download URL: graphql_schema_diff-0.0.3-py3-none-any.whl
  • Upload date:
  • Size: 44.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/42.0.2 requests-toolbelt/0.9.1 tqdm/4.41.0 CPython/3.6.10

File hashes

Hashes for graphql_schema_diff-0.0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 5f7de727d81d205939f669aa4e63aefd8c562ed4929e0795c6dfe0247d9d973e
MD5 d085795354cff04b7eff26b5357c7803
BLAKE2b-256 7da569c8b65ca56eddfe275fec344209cfe404a8d3aba40ab9628a9659265662

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page