@apollo/federation
Version:
Apollo Federation Utilities
34 lines • 1.69 kB
JavaScript
Object.defineProperty(exports, "__esModule", { value: true });
exports.noFed2Subgraphs = void 0;
const graphql_1 = require("graphql");
const utils_1 = require("../../utils");
const noFed2Subgraphs = ({ name: serviceName, typeDefs, }) => {
const errors = [];
(0, graphql_1.visit)(typeDefs, {
SchemaExtension(schemaExtensionNode) {
const directives = (0, utils_1.findDirectivesOnNode)(schemaExtensionNode, 'link').filter(directive => {
var _a;
if (directive.name.value === 'link') {
const argNode = (_a = directive.arguments) === null || _a === void 0 ? void 0 : _a.find(arg => arg.name.value === 'url');
if (argNode) {
if (argNode.value.kind === graphql_1.Kind.STRING) {
const url = argNode.value.value;
const [, spec, versionRaw] = url.match(/(federation|link)\/v(\d+\.\d+)/);
const version = parseFloat(versionRaw);
return ((spec === 'federation' && version >= 2.0) ||
(spec === 'link' && version >= 1.0));
}
}
}
return false;
});
if (directives.length > 0) {
errors.push((0, utils_1.errorWithCode)('NO_FED2_SUBGRAPHS', `[${serviceName}] Schema contains a Federation 2 subgraph. Only federation 1 subgraphs can be composed with the fed1 composer.`));
}
},
});
return errors;
};
exports.noFed2Subgraphs = noFed2Subgraphs;
//# sourceMappingURL=noFed2Subgraphs.js.map
;