UNPKG

@graphql-inspector/core

Version:

Tooling for GraphQL. Compare GraphQL Schemas, check documents, find breaking changes, find similar types.

28 lines (27 loc) 1.2 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.changesInUnion = changesInUnion; const graphql_1 = require("graphql"); const compare_js_1 = require("../utils/compare.js"); const directive_usage_js_1 = require("./changes/directive-usage.js"); const union_js_1 = require("./changes/union.js"); function changesInUnion(oldUnion, newUnion, addChange) { const oldTypes = oldUnion.getTypes(); const newTypes = newUnion.getTypes(); (0, compare_js_1.compareLists)(oldTypes, newTypes, { onAdded(t) { addChange((0, union_js_1.unionMemberAdded)(newUnion, t)); }, onRemoved(t) { addChange((0, union_js_1.unionMemberRemoved)(oldUnion, t)); }, }); (0, compare_js_1.compareLists)(oldUnion.astNode?.directives || [], newUnion.astNode?.directives || [], { onAdded(directive) { addChange((0, directive_usage_js_1.directiveUsageAdded)(graphql_1.Kind.UNION_TYPE_DEFINITION, directive, newUnion)); }, onRemoved(directive) { addChange((0, directive_usage_js_1.directiveUsageRemoved)(graphql_1.Kind.UNION_TYPE_DEFINITION, directive, oldUnion)); }, }); }