UNPKG

@theguild/federation-composition

Version:
26 lines (25 loc) 1.15 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.ContextualArgumentRule = ContextualArgumentRule; const graphql_1 = require("graphql"); function ContextualArgumentRule(context) { return { ObjectTypeFieldArg(objectState, fieldState, argState) { if (!argState.fromContext) { return; } const isRequiredSomewhere = Array.from(argState.byGraph.values()).some((argInGraph) => !argInGraph.fromContext && argInGraph.type.endsWith("!") && !argInGraph.defaultValue); if (!isRequiredSomewhere) { return; } const coordinate = `${objectState.name}.${fieldState.name}(${argState.name}:)`; context.reportError(new graphql_1.GraphQLError(`Argument "${coordinate}" is contextual in at least one subgraph but in "${coordinate}" it does not have @fromContext, is not nullable and has no default value.`, { extensions: { code: "CONTEXTUAL_ARGUMENT_NOT_CONTEXTUAL_IN_ALL_SUBGRAPHS", }, })); }, }; }