
Product
Introducing Webhook Events for Alert Changes
Add real-time Socket webhook events to your workflows to automatically receive software supply chain alert changes in real time.
@beforeyoubid/graphql-schema-diff
Advanced tools
Diff GraphQL schemas to find differences between schema versions
Diff GraphQL schemas to find differences between schema versions
Install by typing
npm install @beforeyoubid/graphql-schema-diff
yarn add @beforeyoubid/graphql-schema-diff
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();
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);
config.showDeprecatedAlongsideRegularRemovalsThe parameter showDeprecatedAlongsideRegularRemovals controls whether removed fields/types that were marked deprecated
show in the removed mismatch outputs.
This defaults to false.
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.compareSchemasThis function will result in an object containing the mismatches between the two schema versions. This object is explained below in the mismatches section
MismatchesMismatches 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.addedTypesaddedTypes includes a list of GraphQL types added in the new schema. (either Object type) or Input type)
Mismatches.removedTypesremovedTypes 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.removedDeprecatedFieldsremovedDeprecatedFields 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.typesMadeDeprecatedtypesMadeDeprecated 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.addedFieldsaddedFields includes a list of fields newly added to the new schema. This list includes the type that the field
is attached to also
Mismatches.removedFieldsremovedFields 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.removedDeprecatedFieldsremovedDeprecatedFields 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.fieldsMadeNotNullfieldsMadeNotNull 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.addedScalarsaddedScalars includes a list of scalars added in the new schema that were not in the previous schema.
Mismatches.removedScalarsremovedScalars includes a list of scalars removed in the new schema that were in the previous schema.
Mismatches.fieldTypesChangedfieldTypesChanged includes a list of fields that had their type changed (ie from Int to String) (either
Object type or Input type)
Mismatches.addedArgumentsaddedArguments 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.addedNotNullArgumentsaddedNotNullArguments 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.removedArgumentsremovedArguments 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.argumentTypesChangedargumentTypesChanged 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.argumentsMadeNotNullargumentsMadeNotNull 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.argumentsMadeNullableargumentsMadeNullable 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.typesChangedtypesChanged includes a list of types that had their type changed (ie from Input to Type or vice-versa).
FAQs
Diff GraphQL schemas to find differences between schema versions
The npm package @beforeyoubid/graphql-schema-diff receives a total of 79 weekly downloads. As such, @beforeyoubid/graphql-schema-diff popularity was classified as not popular.
We found that @beforeyoubid/graphql-schema-diff demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 8 open source maintainers collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Product
Add real-time Socket webhook events to your workflows to automatically receive software supply chain alert changes in real time.

Security News
ENISA has become a CVE Program Root, giving the EU a central authority for coordinating vulnerability reporting, disclosure, and cross-border response.

Product
Socket now scans OpenVSX extensions, giving teams early detection of risky behaviors, hidden capabilities, and supply chain threats in developer tools.