Extensions for graphql-js to support diffing and merging types and schemas.
Install it
npm install --save graphql-schema-utils
Require it
# graphql-js prototypes are automatically extended
require('graphql-schema-utils');
Use it
# Operate on GraphQLSchemas
const thisSchema = buildSchema(...);
const otherSchema = buildSchema(...);
const diffs = schema1.diff(schema2);
const mergedSchema = schema1.merge(schema2);
# Operate on GraphQL types
const thisType = new GraphQLObjectType(...);
const otherType = new GraphQLObjectType(...);
const diffs = thisType.diff(otherType);
const mergedType = thisType.merge(otherType);
- GraphQLSchema
GraphQL schema.
- GraphQLUnionType
GraphQL union type.
- GraphQLObjectType
GraphQL object type.
- GraphQLInterfaceType
GraphQL interface type.
- GraphQLScalarType
GraphQL scalar type.
- GraphQLEnumType
GraphQL enum type.
- GraphQLInputObjectType
GraphQL input object type.
- GraphQLDiff
Object containing metadata about a diff between two GraphQL types.
- DiffType :
Object
Constants representing valid types of GraphQLDiffs.
GraphQL schema.
Kind: global external
See: https://github.com/graphql/graphql-js/blob/master/src/type/schema.js
- GraphQLSchema
- .diff(other, [options]) ⇒
Array.<GraphQLDiff>
- .merge(other) ⇒
GraphQLSchema
- .diff(other, [options]) ⇒
Reports differences between this GraphQLSchema and another one by diffing all of the types.
Kind: instance method of GraphQLSchema
Returns: Array.<GraphQLDiff>
- array of differences between the schemas
Param | Type | Default | Description |
---|---|---|---|
other | GraphQLSchema |
another GraphQLSchema | |
[options] | Object |
optional properties to modify the behavior of the diff operation | |
[options.labelForThis] | String |
"this schema" |
specifies a custom name to refer to the schema on which .diff(...) was called. |
[options.labelForOther] | String |
"other schema" |
specifies a custom name to refer to the schema against which this schema is being diffed. |
Merge this GraphQLSchema with another one. This schema's types and fields take precedence over other's. Does not modify either schema, but instead returns a new one.
Kind: instance method of GraphQLSchema
Returns: GraphQLSchema
- new GraphQLSchema representing this merged with other
Param | Type | Description |
---|---|---|
other | GraphQLSchema |
another GraphQLSchema to merge with this one |
GraphQL union type.
Kind: global external
See: https://github.com/graphql/graphql-js/blob/master/src/type/definition.js
- GraphQLUnionType
- .diff(other, [options]) ⇒
Array.<GraphQLDiff>
- .merge(other) ⇒
GraphQLUnionType
- .diff(other, [options]) ⇒
Reports differences between this GraphQLUnionType and another GraphQLUnionType.
Kind: instance method of GraphQLUnionType
Returns: Array.<GraphQLDiff>
- array of differences
Param | Type | Default | Description |
---|---|---|---|
other | GraphQLUnionType |
another GraphQLUnionType | |
[options] | Object |
optional properties to modify the behavior of the diff operation | |
[options.labelForThis] | String |
"this type" |
specifies a custom name to refer to the object on which .diff(...) was called. |
[options.labelForOther] | String |
"other type" |
specifies a custom name to refer to the object against which this object is being diffed. |
Merges this GraphQLUnionType with another GraphQLUnionType by taking the union of the types included in both.
Kind: instance method of GraphQLUnionType
Returns: GraphQLUnionType
- a new GraphQLUnionType resulting from merging this
and other
Param | Description |
---|---|
other | another GraphQLUnionType to merge with this one |
GraphQL object type.
Kind: global external
See: https://github.com/graphql/graphql-js/blob/master/src/type/definition.js
- GraphQLObjectType
- .diff(other, [options]) ⇒
Array.<GraphQLDiff>
- .merge(other) ⇒
GraphQLObjectType
|GraphQLInterfaceType
|GraphQLInputObjectType
- .diff(other, [options]) ⇒
Reports differences between this GraphQLObjectType, GraphQLInterfaceType, or GraphQLInputObjectType and another. Fields and implemented interfaces are compared.
Kind: instance method of GraphQLObjectType
Returns: Array.<GraphQLDiff>
- array of differences
Param | Type | Default | Description |
---|---|---|---|
other | GraphQLObjectType | GraphQLInterfaceType | GraphQLInputObjectType |
another GraphQLObjectType, GraphQLInterfaceType, or GraphQLInputObjectType | |
[options] | Object |
optional properties to modify the behavior of the diff operation | |
[options.labelForThis] | String |
"this type" |
specifies a custom name to refer to the object on which .diff(...) was called. |
[options.labelForOther] | String |
"other type" |
specifies a custom name to refer to the object against which this object is being diffed. |
Merges another GraphQLObjectType or GraphQLInterfaceType with this one by taking the union of all fields in both types, overwriting this type's fields with the other's if there are conflicts. For GraphQLObjectTypes, implemented interfaces are also merged.
Kind: instance method of GraphQLObjectType
Returns: GraphQLObjectType
| GraphQLInterfaceType
| GraphQLInputObjectType
- a new graphql type resulting from merging this
and other
Param | Description |
---|---|
other | another GraphQL type to merge with this one |
GraphQL interface type.
Kind: global external
See: https://github.com/graphql/graphql-js/blob/master/src/type/definition.js
- GraphQLInterfaceType
- .diff(other, [options]) ⇒
Array.<GraphQLDiff>
- .merge(other) ⇒
GraphQLObjectType
|GraphQLInterfaceType
|GraphQLInputObjectType
- .diff(other, [options]) ⇒
Reports differences between this GraphQLObjectType, GraphQLInterfaceType, or GraphQLInputObjectType and another. Fields and implemented interfaces are compared.
Kind: instance method of GraphQLInterfaceType
Returns: Array.<GraphQLDiff>
- array of differences
Param | Type | Default | Description |
---|---|---|---|
other | GraphQLObjectType | GraphQLInterfaceType | GraphQLInputObjectType |
another GraphQLObjectType, GraphQLInterfaceType, or GraphQLInputObjectType | |
[options] | Object |
optional properties to modify the behavior of the diff operation | |
[options.labelForThis] | String |
"this type" |
specifies a custom name to refer to the object on which .diff(...) was called. |
[options.labelForOther] | String |
"other type" |
specifies a custom name to refer to the object against which this object is being diffed. |
graphQLInterfaceType.merge(other) ⇒ GraphQLObjectType
| GraphQLInterfaceType
| GraphQLInputObjectType
Merges another GraphQLObjectType or GraphQLInterfaceType with this one by taking the union of all fields in both types, overwriting this type's fields with the other's if there are conflicts. For GraphQLObjectTypes, implemented interfaces are also merged.
Kind: instance method of GraphQLInterfaceType
Returns: GraphQLObjectType
| GraphQLInterfaceType
| GraphQLInputObjectType
- a new graphql type resulting from merging this
and other
Param | Description |
---|---|
other | another GraphQL type to merge with this one |
GraphQL scalar type.
Kind: global external
See: https://github.com/graphql/graphql-js/blob/master/src/type/definition.js
Reports differences between this GraphQLScalarType and another.
Kind: instance method of GraphQLScalarType
Returns: Array.<GraphQLDiff>
- array of differences
Param | Type | Default | Description |
---|---|---|---|
other | GraphQLScalarType |
another GraphQLScalarType | |
[options] | Object |
optional properties to modify the behavior of the diff operation | |
[options.labelForThis] | String |
"this type" |
specifies a custom name to refer to the object on which .diff(...) was called. |
[options.labelForOther] | String |
"other type" |
specifies a custom name to refer to the object against which this object is being diffed. |
GraphQL enum type.
Kind: global external
See: https://github.com/graphql/graphql-js/blob/master/src/type/definition.js
- GraphQLEnumType
- .diff(other, [options]) ⇒
Array.<GraphQLDiff>
- .merge(other) ⇒
GraphQLList
|GraphQLNonNull
|GraphQLScalarType
|GraphQLEnumType
- .diff(other, [options]) ⇒
Reports differences between this GraphQLEnumType and another. The name and enum values are compared.
Kind: instance method of GraphQLEnumType
Returns: Array.<GraphQLDiff>
- array of differences
Param | Type | Default | Description |
---|---|---|---|
other | GraphQLEnumType |
another GraphQLEnumType | |
[options] | Object |
optional properties to modify the behavior of the diff operation | |
[options.labelForThis] | String |
"this type" |
specifies a custom name to refer to the object on which .diff(...) was called. |
[options.labelForOther] | String |
"other type" |
specifies a custom name to refer to the object against which this object is being diffed. |
Merges a type by simply overwriting this type with other if it exists.
Kind: instance method of GraphQLEnumType
Returns: GraphQLList
| GraphQLNonNull
| GraphQLScalarType
| GraphQLEnumType
- other if it exists, otherwise this.
Param | Type | Description |
---|---|---|
other | GraphQLList | GraphQLNonNull | GraphQLScalarType | GraphQLEnumType |
another GraphQL type object to merge with this |
GraphQL input object type.
Kind: global external
See: https://github.com/graphql/graphql-js/blob/master/src/type/definition.js
- GraphQLInputObjectType
- .diff(other, [options]) ⇒
Array.<GraphQLDiff>
- .merge(other) ⇒
GraphQLObjectType
|GraphQLInterfaceType
|GraphQLInputObjectType
- .diff(other, [options]) ⇒
Reports differences between this GraphQLObjectType, GraphQLInterfaceType, or GraphQLInputObjectType and another. Fields and implemented interfaces are compared.
Kind: instance method of GraphQLInputObjectType
Returns: Array.<GraphQLDiff>
- array of differences
Param | Type | Default | Description |
---|---|---|---|
other | GraphQLObjectType | GraphQLInterfaceType | GraphQLInputObjectType |
another GraphQLObjectType, GraphQLInterfaceType, or GraphQLInputObjectType | |
[options] | Object |
optional properties to modify the behavior of the diff operation | |
[options.labelForThis] | String |
"this type" |
specifies a custom name to refer to the object on which .diff(...) was called. |
[options.labelForOther] | String |
"other type" |
specifies a custom name to refer to the object against which this object is being diffed. |
graphQLInputObjectType.merge(other) ⇒ GraphQLObjectType
| GraphQLInterfaceType
| GraphQLInputObjectType
Merges another GraphQLObjectType or GraphQLInterfaceType with this one by taking the union of all fields in both types, overwriting this type's fields with the other's if there are conflicts. For GraphQLObjectTypes, implemented interfaces are also merged.
Kind: instance method of GraphQLInputObjectType
Returns: GraphQLObjectType
| GraphQLInterfaceType
| GraphQLInputObjectType
- a new graphql type resulting from merging this
and other
Param | Description |
---|---|
other | another GraphQL type to merge with this one |
Object containing metadata about a diff between two GraphQL types.
Create a new instance of a GraphQLDiff, containing metadata about a difference between two GraphQL types.
Param | Type | Description |
---|---|---|
thisType | GraphQLObjectType | GraphQLScalarType | GraphQLEnumType | GraphQLNonNull | GraphQLList | GraphQLUnionType |
the GraphQL type instance on which the diff method was executed |
otherType | GraphQLObjectType | GraphQLScalarType | GraphQLEnumType | GraphQLNonNull | GraphQLList | GraphQLUnionType |
the GraphQL type instance which was compared to thisType |
diffType | string |
the specific kind of difference between thisType and otherType |
description | string |
|
backwardsCompatible | boolean |
true if this is a non-breaking change when interpreted as thisType changing to otherType |
Constants representing valid types of GraphQLDiffs.
Kind: global constant