@theguild/federation-composition
Version:
Open Source Composition library for Apollo Federation
29 lines (28 loc) • 1.5 kB
JavaScript
"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(` 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 (without label) for this migration.`, {
extensions: {
code: "OVERRIDE_COLLISION_WITH_ANOTHER_DIRECTIVE",
},
}));
}
},
};
}