UNPKG

@theguild/federation-composition

Version:
29 lines (28 loc) 1.5 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.OverrideLabelWithRequiresRule = OverrideLabelWithRequiresRule; const graphql_1 = require("graphql"); function OverrideLabelWithRequiresRule(context) { return { ObjectTypeField(objectTypeState, fieldState) { for (const [graphId, fieldStateInGraph] of fieldState.byGraph) { if (!fieldStateInGraph.override || !fieldStateInGraph.overrideLabel) { continue; } const sourceGraphId = context.graphNameToId(fieldStateInGraph.override); if (!sourceGraphId) { continue; } const sourceFieldStateInGraph = fieldState.byGraph.get(sourceGraphId); if (!sourceFieldStateInGraph?.requires) { continue; } context.reportError(new graphql_1.GraphQLError(`@override with label (progressive override) cannot be used on field "${objectTypeState.name}.${fieldState.name}" on subgraph "${context.graphIdToName(graphId)}" since "${objectTypeState.name}.${fieldState.name}" on "${context.graphIdToName(sourceGraphId)}" is marked with directive "@requires". Use non-progressive @override (without label) for this migration.`, { extensions: { code: "OVERRIDE_COLLISION_WITH_ANOTHER_DIRECTIVE", }, })); } }, }; }