UNPKG

@graphql-inspector/cli

Version:

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

29 lines (28 loc) 1.31 kB
import { Kind } from 'graphql'; import { compareDirectiveLists, compareLists } from '../utils/compare.js'; import { directiveUsageAdded, directiveUsageChanged, directiveUsageRemoved, } from './changes/directive-usage.js'; import { unionMemberAdded, unionMemberRemoved } from './changes/union.js'; export function changesInUnion(oldUnion, newUnion, addChange) { const oldTypes = oldUnion?.getTypes() ?? []; const newTypes = newUnion.getTypes(); compareLists(oldTypes, newTypes, { onAdded(t) { addChange(unionMemberAdded(newUnion, t, oldUnion === null)); }, onRemoved(t) { addChange(unionMemberRemoved(oldUnion, t)); }, }); compareDirectiveLists(oldUnion?.astNode?.directives || [], newUnion.astNode?.directives || [], { onAdded(directive) { addChange(directiveUsageAdded(Kind.UNION_TYPE_DEFINITION, directive, newUnion, oldUnion === null)); directiveUsageChanged(null, directive, addChange, newUnion); }, onMutual(directive) { directiveUsageChanged(directive.oldVersion, directive.newVersion, addChange, newUnion); }, onRemoved(directive) { addChange(directiveUsageRemoved(Kind.UNION_TYPE_DEFINITION, directive, oldUnion)); }, }); }