An open API service indexing awesome lists of open source software.

https://github.com/jarwol/graphql-schema-utils

Extensions for graphql-js to support diffing and merging types and schemas.
https://github.com/jarwol/graphql-schema-utils

graphql graphql-js

Last synced: 5 months ago
JSON representation

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

Awesome Lists containing this project

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](https://github.com/graphql/graphql-js/blob/master/src/type/schema.js)

* [GraphQLSchema](#external_GraphQLSchema)
* [.diff(other, [options])](#external_GraphQLSchema+diff) ⇒ Array.<GraphQLDiff>
* [.merge(other)](#external_GraphQLSchema+merge) ⇒ 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](#external_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](#external_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](https://github.com/graphql/graphql-js/blob/master/src/type/definition.js)

* [GraphQLUnionType](#external_GraphQLUnionType)
* [.diff(other, [options])](#external_GraphQLUnionType+diff) ⇒ Array.<GraphQLDiff>
* [.merge(other)](#external_GraphQLUnionType+merge) ⇒ GraphQLUnionType

### graphQLUnionType.diff(other, [options]) ⇒ Array.<GraphQLDiff>
Reports differences between this GraphQLUnionType and another GraphQLUnionType.

**Kind**: instance method of [GraphQLUnionType](#external_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](#external_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](https://github.com/graphql/graphql-js/blob/master/src/type/definition.js)

* [GraphQLObjectType](#external_GraphQLObjectType)
* [.diff(other, [options])](#external_GraphQLObjectType+diff) ⇒ Array.<GraphQLDiff>
* [.merge(other)](#external_GraphQLObjectType+merge) ⇒ 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](#external_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](#external_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](https://github.com/graphql/graphql-js/blob/master/src/type/definition.js)

* [GraphQLInterfaceType](#external_GraphQLInterfaceType)
* [.diff(other, [options])](#external_GraphQLInterfaceType+diff) ⇒ Array.<GraphQLDiff>
* [.merge(other)](#external_GraphQLInterfaceType+merge) ⇒ 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](#external_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](#external_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](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](#external_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](https://github.com/graphql/graphql-js/blob/master/src/type/definition.js)

* [GraphQLEnumType](#external_GraphQLEnumType)
* [.diff(other, [options])](#external_GraphQLEnumType+diff) ⇒ Array.<GraphQLDiff>
* [.merge(other)](#external_GraphQLEnumType+merge) ⇒ 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](#external_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](#external_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](https://github.com/graphql/graphql-js/blob/master/src/type/definition.js)

* [GraphQLInputObjectType](#external_GraphQLInputObjectType)
* [.diff(other, [options])](#external_GraphQLInputObjectType+diff) ⇒ Array.<GraphQLDiff>
* [.merge(other)](#external_GraphQLInputObjectType+merge) ⇒ 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](#external_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](#external_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