UNPKG

@graphql-inspector/core

Version:

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

23 lines (22 loc) 851 B
import { getReachableTypes } from '../../utils/graphql.js'; import { parsePath } from '../../utils/path.js'; import { CriticalityLevel } from '../changes/change.js'; export const safeUnreachable = ({ changes, oldSchema }) => { const reachable = getReachableTypes(oldSchema); return changes.map(change => { if (change.criticality.level === CriticalityLevel.Breaking && change.path) { const [typeName] = parsePath(change.path); if (!reachable.has(typeName)) { return { ...change, criticality: { ...change.criticality, level: CriticalityLevel.NonBreaking, }, message: 'Unreachable from root', }; } } return change; }); };