@@ -3,12 +3,13 @@ import { ApolloServer } from 'apollo-server-express';
33import { Router } from 'express' ;
44import expressPlayground from 'graphql-playground-middleware-express' ;
55
6- import getConfigObject , { initializeSets } from './config' ;
6+ import { mergeSchemas } from '@graphql-tools/schema' ;
7+ import getConfigObject , { ENV_CONFIG , initializeSets } from './config' ;
78import { DEBUG_MODE , ES_PASS , ES_USER } from './config/constants' ;
89import { ConfigProperties } from './config/types' ;
910import { addMappingsToTypes , extendFields , fetchMapping } from './mapping' ;
1011import { extendColumns , extendFacets , flattenMappingToFields } from './mapping/extendMapping' ;
11- import { createSchemaFromNetworkConfig , mergeSchemas } from './network' ;
12+ import { createSchemaFromNetworkConfig } from './network' ;
1213import makeSchema from './schema' ;
1314
1415const getESMapping = async ( esClient , index ) => {
@@ -156,32 +157,13 @@ const noSchemaHandler =
156157 } ) ;
157158 } ;
158159
159- const createEndpoint = async ( {
160- esClient,
161- graphqlOptions = { } ,
162- mockSchema,
163- schema,
164- networkSchema,
165- } ) => {
160+ const createEndpoint = async ( { esClient, graphqlOptions = { } , mockSchema, schema } ) => {
166161 const mainPath = '/graphql' ;
167162 const mockPath = '/mock/graphql' ;
168163 const router = Router ( ) ;
169164
170165 console . log ( 'Starting GraphQL server:' ) ;
171166
172- if ( ENABLE_NETWORK_AGGREGATION ) {
173- /**
174- * TODO: make available on one route
175- */
176- const networkPath = '/network' ;
177- const apolloNetworkServer = new ApolloServer ( {
178- cache : 'bounded' ,
179- schema : networkSchema ,
180- } ) ;
181- await apolloNetworkServer . start ( ) ;
182- apolloNetworkServer . applyMiddleware ( { app : router , path : networkPath } ) ;
183- }
184-
185167 try {
186168 await router . get (
187169 mainPath ,
@@ -261,10 +243,11 @@ const createEndpoint = async ({
261243 return router ;
262244} ;
263245
264- export const createSchemasFromConfigs = async ( {
246+ const createSchemasFromConfigs = async ( {
265247 configsSource = '' ,
266248 enableAdmin,
267249 enableDocumentHits,
250+ enableNetworkAggregation,
268251 esClient,
269252 getServerSideFilter,
270253 graphqlOptions = { } ,
@@ -287,28 +270,30 @@ export const createSchemasFromConfigs = async ({
287270 types : typesWithMappings ,
288271 } ) ;
289272
290- /**
273+ const schemasToMerge = [ schema ] ;
274+
275+ /*
291276 * Federated Network Search
292277 */
293- if ( ENABLE_NETWORK_AGGREGATION ) {
294- const { networkSchema } = await createSchemaFromNetworkConfig ( {
278+ if ( enableNetworkAggregation ) {
279+ const networkSchema = await createSchemaFromNetworkConfig ( {
295280 networkConfigs : configsFromFiles [ ConfigProperties . NETWORK_AGGREGATION ] . map ( ( config ) => ( {
296281 ...config ,
297- /**
282+ /*
298283 * part of the gql schema is generated dynamically
299- * in the case of the "file" field, the field name and type name are the same
300- * it's more flexible to define it here as an additional property than to confuse functions further down the pipeline
284+ * in the case of the "file" field, the field name and gql type name are the same
301285 */
302286 documentName : config . documentType ,
303287 } ) ) ,
304288 } ) ;
289+ schemasToMerge . push ( networkSchema ) ;
305290 }
306291
292+ const fullSchema = mergeSchemas ( { schemas : schemasToMerge } ) ;
307293 return {
308294 ...commonFields ,
309295 mockSchema,
310- schema,
311- networkSchema,
296+ schema : fullSchema ,
312297 } ;
313298 } catch ( error ) {
314299 const message = error ?. message || error ;
@@ -323,16 +308,18 @@ export default async ({
323308 configsSource = '' ,
324309 enableAdmin,
325310 enableDocumentHits,
311+ enableNetworkAggregation,
326312 esClient,
327313 getServerSideFilter,
328314 graphqlOptions = { } ,
329315} ) => {
330316 try {
331- const { fieldsFromMapping, mockSchema, schema, typesWithMappings, networkSchema } =
317+ const { fieldsFromMapping, mockSchema, schema, typesWithMappings } =
332318 await createSchemasFromConfigs ( {
333319 configsSource,
334320 enableAdmin,
335321 enableDocumentHits,
322+ enableNetworkAggregation,
336323 esClient,
337324 getServerSideFilter,
338325 graphqlOptions,
@@ -343,7 +330,6 @@ export default async ({
343330 graphqlOptions,
344331 mockSchema,
345332 schema,
346- networkSchema,
347333 } ) ;
348334
349335 await initializeSets ( { esClient } ) ;
0 commit comments