UNPKG

@graphql-inspector/core

Version:

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

25 lines (24 loc) 992 B
import { Kind } from 'graphql'; import { compareLists } from '../utils/compare.js'; import { directiveUsageAdded, 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)); }, onRemoved(t) { addChange(unionMemberRemoved(oldUnion, t)); }, }); compareLists(oldUnion.astNode?.directives || [], newUnion.astNode?.directives || [], { onAdded(directive) { addChange(directiveUsageAdded(Kind.UNION_TYPE_DEFINITION, directive, newUnion)); }, onRemoved(directive) { addChange(directiveUsageRemoved(Kind.UNION_TYPE_DEFINITION, directive, oldUnion)); }, }); }