UNPKG

@graphql-inspector/cli

Version:

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

40 lines (39 loc) 2.01 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.unionMemberAdded = unionMemberAdded; exports.unionMemberRemoved = unionMemberRemoved; const errors_js_1 = require("../errors.js"); const node_templates_js_1 = require("../node-templates.js"); const utils_js_1 = require("../utils.js"); function unionMemberAdded(change, nodeByPath, config, _context) { if (!change.path) { config.onError(new errors_js_1.ChangePathMissingError(change), change); return; } const union = nodeByPath.get((0, utils_js_1.parentPath)(change.path)); if (!union) { config.onError(new errors_js_1.ChangedAncestorCoordinateNotFoundError(change.path, change.type, change.meta.addedUnionMemberTypeName), change); return; } if ((0, utils_js_1.findNamedNode)(union.types, change.meta.addedUnionMemberTypeName)) { config.onError(new errors_js_1.AddedAttributeAlreadyExistsError(change.path, change.type, 'types', change.meta.addedUnionMemberTypeName), change); return; } union.types = [...(union.types ?? []), (0, node_templates_js_1.namedTypeNode)(change.meta.addedUnionMemberTypeName)]; } function unionMemberRemoved(change, nodeByPath, config, _context) { if (!change.path) { config.onError(new errors_js_1.ChangePathMissingError(change), change); return; } const union = nodeByPath.get((0, utils_js_1.parentPath)(change.path)); if (!union) { config.onError(new errors_js_1.DeletedAncestorCoordinateNotFoundError(change.path, change.type, change.meta.removedUnionMemberTypeName), change); return; } if (!(0, utils_js_1.findNamedNode)(union.types, change.meta.removedUnionMemberTypeName)) { config.onError(new errors_js_1.DeletedAttributeNotFoundError(change.path, change.type, 'types', change.meta.removedUnionMemberTypeName), change); return; } union.types = union.types.filter(t => t.name.value !== change.meta.removedUnionMemberTypeName); }