gsu

graphql-schema-utils

Extensions for graphql-js to support diffing and merging types and schemas.

Showing:

Popularity

Downloads/wk

12

GitHub Stars

10

Maintenance

Last Commit

3yrs ago

Contributors

7

Package

Dependencies

1

License

MIT

Type Definitions

Tree-Shakeable

No?

Categories

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

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.

Constants

DiffType : Object

Constants representing valid types of GraphQLDiffs.

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>

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

ParamTypeDefaultDescription
otherGraphQLSchemaanother GraphQLSchema
[options]Objectoptional 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

ParamTypeDescription
otherGraphQLSchemaanother 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>

Reports differences between this GraphQLUnionType and another GraphQLUnionType.

Kind: instance method of GraphQLUnionType
Returns: Array.<GraphQLDiff> - array of differences

ParamTypeDefaultDescription
otherGraphQLUnionTypeanother GraphQLUnionType
[options]Objectoptional 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

ParamDescription
otheranother 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>

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

ParamTypeDefaultDescription
otherGraphQLObjectType | GraphQLInterfaceType | GraphQLInputObjectTypeanother GraphQLObjectType, GraphQLInterfaceType, or GraphQLInputObjectType
[options]Objectoptional 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

ParamDescription
otheranother 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>

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

ParamTypeDefaultDescription
otherGraphQLObjectType | GraphQLInterfaceType | GraphQLInputObjectTypeanother GraphQLObjectType, GraphQLInterfaceType, or GraphQLInputObjectType
[options]Objectoptional 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

ParamDescription
otheranother 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

ParamTypeDefaultDescription
otherGraphQLScalarTypeanother GraphQLScalarType
[options]Objectoptional 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>

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

ParamTypeDefaultDescription
otherGraphQLEnumTypeanother GraphQLEnumType
[options]Objectoptional 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.

ParamTypeDescription
otherGraphQLList | GraphQLNonNull | GraphQLScalarType | GraphQLEnumTypeanother 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>

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

ParamTypeDefaultDescription
otherGraphQLObjectType | GraphQLInterfaceType | GraphQLInputObjectTypeanother GraphQLObjectType, GraphQLInterfaceType, or GraphQLInputObjectType
[options]Objectoptional 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

ParamDescription
otheranother 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.

ParamTypeDescription
thisTypeGraphQLObjectType | GraphQLScalarType | GraphQLEnumType | GraphQLNonNull | GraphQLList | GraphQLUnionTypethe GraphQL type instance on which the diff method was executed
otherTypeGraphQLObjectType | GraphQLScalarType | GraphQLEnumType | GraphQLNonNull | GraphQLList | GraphQLUnionTypethe GraphQL type instance which was compared to thisType
diffTypestringthe specific kind of difference between thisType and otherType
descriptionstring
backwardsCompatiblebooleantrue 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

Rate & Review

Great Documentation0
Easy to Use0
Performant0
Highly Customizable0
Bleeding Edge0
Responsive Maintainers0
Poor Documentation0
Hard to Use0
Slow0
Buggy0
Abandoned0
Unwelcoming Community0
100
No reviews found
Be the first to rate

Alternatives

No alternatives found

Tutorials

No tutorials found
Add a tutorial