1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | exports.GraphQLFederationDefinitionsFactory = void 0;
|
4 | const load_package_util_1 = require("@nestjs/common/utils/load-package.util");
|
5 | const graphql_tag_1 = require("graphql-tag");
|
6 | const graphql_definitions_factory_1 = require("../graphql-definitions.factory");
|
7 | const utils_1 = require("../utils");
|
8 | const merge_1 = require("@graphql-tools/merge");
|
9 | class GraphQLFederationDefinitionsFactory extends graphql_definitions_factory_1.GraphQLDefinitionsFactory {
|
10 | async exploreAndEmit(typePaths, path, outputAs, isDebugEnabled, definitionsGeneratorOptions, typeDefs) {
|
11 | const typePathDefs = await this.gqlTypesLoader.mergeTypesByPaths(typePaths);
|
12 | const mergedTypeDefs = (0, utils_1.extend)(typePathDefs, typeDefs);
|
13 | const { buildSubgraphSchema } = (0, load_package_util_1.loadPackage)('@apollo/subgraph', 'ApolloFederation', () => require('@apollo/subgraph'));
|
14 | const { printSubgraphSchema } = (0, load_package_util_1.loadPackage)('@apollo/subgraph', 'ApolloFederation', () => require('@apollo/subgraph'));
|
15 | const schema = buildSubgraphSchema([
|
16 | {
|
17 | typeDefs: (0, graphql_tag_1.gql) `
|
18 | ${mergedTypeDefs}
|
19 | `,
|
20 | resolvers: {},
|
21 | },
|
22 | ]);
|
23 |
|
24 |
|
25 |
|
26 | const mergedDefinition = (0, merge_1.mergeTypeDefs)([printSubgraphSchema(schema)], {
|
27 | useSchemaDefinition: false,
|
28 | throwOnConflict: true,
|
29 | commentDescriptions: true,
|
30 | reverseDirectives: true,
|
31 | });
|
32 | const tsFile = await this.gqlAstExplorer.explore((0, graphql_tag_1.gql) `
|
33 | ${mergedDefinition}
|
34 | `, path, outputAs, definitionsGeneratorOptions);
|
35 | await tsFile.save();
|
36 | this.printMessage(`[${new Date().toLocaleTimeString()}] The definitions have been updated.`, isDebugEnabled);
|
37 | }
|
38 | }
|
39 | exports.GraphQLFederationDefinitionsFactory = GraphQLFederationDefinitionsFactory;
|