graphql-schema-utils
v0.6.7
Published
Extensions for graphql-js to support diffing and merging types and schemas.
Downloads
15
Readme
graphql-schema-utils
Extensions for graphql-js to support diffing and merging types and schemas.
Getting Started
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);
API Docs
Classes
Constants
GraphQLSchema
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
graphQLSchema.diff(other, [options]) ⇒ Array.<GraphQLDiff>
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. |
graphQLSchema.merge(other) ⇒ GraphQLSchema
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 |
GraphQLUnionType
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
graphQLUnionType.diff(other, [options]) ⇒ Array.<GraphQLDiff>
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. |
graphQLUnionType.merge(other) ⇒ GraphQLUnionType
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 |
GraphQLObjectType
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
graphQLObjectType.diff(other, [options]) ⇒ Array.<GraphQLDiff>
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. |
graphQLObjectType.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 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 |
GraphQLInterfaceType
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
graphQLInterfaceType.diff(other, [options]) ⇒ Array.<GraphQLDiff>
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 |
GraphQLScalarType
GraphQL scalar type.
Kind: global external
See: https://github.com/graphql/graphql-js/blob/master/src/type/definition.js
graphQLScalarType.diff(other, [options]) ⇒ Array.<GraphQLDiff>
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. |
GraphQLEnumType
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
graphQLEnumType.diff(other, [options]) ⇒ Array.<GraphQLDiff>
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. |
graphQLEnumType.merge(other) ⇒ GraphQLList | GraphQLNonNull | GraphQLScalarType | GraphQLEnumType
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 |
GraphQLInputObjectType
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
graphQLInputObjectType.diff(other, [options]) ⇒ Array.<GraphQLDiff>
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 |
GraphQLDiff
Object containing metadata about a diff between two GraphQL types.
Kind: global class
new GraphQLDiff(thisType, otherType, diffType, description, backwardsCompatible)
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 |
DiffType : Object
Constants representing valid types of GraphQLDiffs.
Kind: global constant