npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@beforeyoubid/graphql-schema-diff

v0.1.1

Published

Diff GraphQL schemas to find differences between schema versions

Downloads

261

Readme

graphql-schema-diff

Diff GraphQL schemas to find differences between schema versions

Maintainability

Test Coverage

Install

Install by typing

npm install @beforeyoubid/graphql-schema-diff
yarn add @beforeyoubid/graphql-schema-diff

Usage

You can use like the following:

import Schema from '@beforeyoubid/graphql-schema-diff';

const previousSchema = `.....`;
const currentSchema = `.....`;

const schema = new Schema(previousSchema, currentSchema);
const mismatches = await schema.compareSchemas();

Printing

You can print the schema values by using some of the print utils:

import Schema, { printType, printField } from '@beforeyoubid/graphql-schema-diff';

const previousSchema = `.....`;
const currentSchema = `.....`;

const schema = new Schema(previousSchema, currentSchema);
const mismatches = await schema.compareSchemas();

let msg = '';
if (mismatches.addedTypes.length > 0) {
  msg += ` - Added types: ${mismatches.addedTypes.map(printType('green')).map(tilde).join(', ')}`;
}
if (mismatches.removedTypes.length > 0) {
  msg += ` - Removed types: ${mismatches.removedTypes.map(printType('red')).map(tilde).join(', ')}`;
}
if (mismatches.addedFields.length > 0) {
  msg += ` - Added fields: ${mismatches.addedFields.map(printField('green')).map(tilde).join(', ')}`;
}
if (mismatches.removedFields.length > 0) {
  msg += ` - Removed fields: ${mismatches.removedFields.map(printField('red')).map(tilde).join(', ')}`;
}
console.log(msg);

Documentation

Config

config.showDeprecatedAlongsideRegularRemovals

The parameter showDeprecatedAlongsideRegularRemovals controls whether removed fields/types that were marked deprecated show in the removed mismatch outputs.

This defaults to false.

Schema class

The Schema class is instatiated with the following arguments:

  constructor(
    schemaOne: string | DocumentNode, // either a string of the schema, or a GraphQL document node
    schemaTwo: string | DocumentNode, // either a string of the schema, or a GraphQL document node
    config: Config // see config section above
  )

Schema.compareSchemas

This function will result in an object containing the mismatches between the two schema versions. This object is explained below in the mismatches section

Mismatches

Mismatches containes all the differences between the two schemas, typically these are outputted as the AST nodes returned by GraphQL when parsing these documents.

They contain the following properties:

Mismatches.addedTypes

addedTypes includes a list of GraphQL types added in the new schema. (either Object type) or Input type)

Mismatches.removedTypes

removedTypes includes a list of GraphQL types removed in the new schema. (either Object type or Input type)

This will not contain any types that were deprecated in the previous schema, unless the configuration value showDeprecatedAlongsideRegularRemovals is set to true.

Mismatches.removedDeprecatedFields

removedDeprecatedFields includes a list of GraphQL types removed in the new schema that were deprecated in the previous schema. (either Object type or Input type).

This is an array containing the type alongside the reason for deprecation as specified on the @deprecated directive.

Mismatches.typesMadeDeprecated

typesMadeDeprecated includes a list of types newly made deprecated alongside the reason for deprecation as specified on the @deprecated directive. (either Object type or Input type)

Mismatches.addedFields

addedFields includes a list of fields newly added to the new schema. This list includes the type that the field is attached to also

Mismatches.removedFields

removedFields includes a list of fields removed in the new schema. This list includes the type that the field is attached to also

This will not contain any fields that were deprecated in the previous schema, unless the configuration value showDeprecatedAlongsideRegularRemovals is set to true.

Mismatches.removedDeprecatedFields

removedDeprecatedFields includes a list of fields removed in the new schema that were deprecated in the last schema. This list includes the type that the field is attached to also.

Mismatches.fieldsMadeNotNull

fieldsMadeNotNull includes a list of fields that were made not-null in the new schema that were nullable in the last schema. This list includes the type that the field is attached to also.

Mismatches.addedScalars

addedScalars includes a list of scalars added in the new schema that were not in the previous schema.

Mismatches.removedScalars

removedScalars includes a list of scalars removed in the new schema that were in the previous schema.

Mismatches.fieldTypesChanged

fieldTypesChanged includes a list of fields that had their type changed (ie from Int to String) (either Object type or Input type)

Mismatches.addedArguments

addedArguments includes a list of arguments added to fields in the new schema that weren't in the previous schema.

The list of results includes the type and field the argument is attached to.

Mismatches.addedNotNullArguments

addedNotNullArguments includes a list of not null arguments added to fields in the new schema that weren't in the previous schema.

The list of results includes the type and field the argument is attached to.

Mismatches.removedArguments

removedArguments includes a list of arguments removed from fields in the new schema that were in the previous schema.

The list of results includes the type and field the argument is attached to.

Mismatches.argumentTypesChanged

argumentTypesChanged includes a list of arguments on fields that had their type changed between schema versions.

The list of results includes the type and field the argument is attached to.

Mismatches.argumentsMadeNotNull

argumentsMadeNotNull includes a list of arguments on fields that had their type made not null where it was previously nullable.

The list of results includes the type and field the argument is attached to.

Mismatches.argumentsMadeNullable

argumentsMadeNullable includes a list of arguments on fields that had their type made nullable where it was previously not null.

The list of results includes the type and field the argument is attached to.

Mismatches.typesChanged

typesChanged includes a list of types that had their type changed (ie from Input to Type or vice-versa).