UNPKG

@theguild/federation-composition

Version:

Open Source Composition library for Apollo Federation

64 lines (63 loc) 2.25 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.scalarTypeBuilder = void 0; const ast_js_1 = require("./ast.js"); const common_js_1 = require("./common.js"); function scalarTypeBuilder() { return { visitSubgraphState(graph, state, typeName, type) { const scalarTypeState = getOrCreateScalarType(state, typeName); type.tags.forEach(tag => scalarTypeState.tags.add(tag)); if (type.inaccessible) { scalarTypeState.inaccessible = true; } if (type.description && !scalarTypeState.description) { scalarTypeState.description = type.description; } if (type.specifiedBy && !scalarTypeState.specifiedBy) { scalarTypeState.specifiedBy = type.specifiedBy; } type.ast.directives.forEach(directive => { scalarTypeState.ast.directives.push(directive); }); scalarTypeState.byGraph.set(graph.id, { inaccessible: type.inaccessible, }); }, composeSupergraphNode(scalarType) { return (0, ast_js_1.createScalarTypeNode)({ name: scalarType.name, tags: Array.from(scalarType.tags), inaccessible: scalarType.inaccessible, description: scalarType.description, specifiedBy: scalarType.specifiedBy, join: { type: Array.from(scalarType.byGraph.keys()).map(graphName => ({ graph: graphName.toUpperCase(), })), }, ast: { directives: (0, common_js_1.convertToConst)(scalarType.ast.directives), }, }); }, }; } exports.scalarTypeBuilder = scalarTypeBuilder; function getOrCreateScalarType(state, typeName) { const existing = state.get(typeName); if (existing) { return existing; } const def = { name: typeName, tags: new Set(), inaccessible: false, byGraph: new Map(), ast: { directives: [], }, }; state.set(typeName, def); return def; }