diff --git a/lib/federation/graphql-federation.factory.ts b/lib/federation/graphql-federation.factory.ts index 482eb5286..4999169d3 100644 --- a/lib/federation/graphql-federation.factory.ts +++ b/lib/federation/graphql-federation.factory.ts @@ -92,20 +92,25 @@ export class GraphQLFederationFactory { private async generateSchema( options: GqlModuleOptions, ): Promise { - const { - buildFederatedSchema, - printSchema, - } = loadPackage('@apollo/federation', 'ApolloFederation', () => - require('@apollo/federation'), + const { buildFederatedSchema } = loadPackage( + '@apollo/federation', + 'ApolloFederation', + () => require('@apollo/federation'), ); - - const autoGeneratedSchema: GraphQLSchema = await this.gqlSchemaBuilder.buildFederatedSchema( - options.autoSchemaFile, - options, - this.resolversExplorerService.getAllCtors(), + const { printSubgraphSchema } = loadPackage( + '@apollo/subgraph', + 'ApolloFederation', + () => require('@apollo/subgraph'), ); + + const autoGeneratedSchema: GraphQLSchema = + await this.gqlSchemaBuilder.buildFederatedSchema( + options.autoSchemaFile, + options, + this.resolversExplorerService.getAllCtors(), + ); let executableSchema: GraphQLSchema = buildFederatedSchema({ - typeDefs: gql(printSchema(autoGeneratedSchema)), + typeDefs: gql(printSubgraphSchema(autoGeneratedSchema)), resolvers: this.getResolvers(options.resolvers), }); diff --git a/lib/federation/graphql-federation.module.ts b/lib/federation/graphql-federation.module.ts index ca2dd4f18..fb787d13e 100644 --- a/lib/federation/graphql-federation.module.ts +++ b/lib/federation/graphql-federation.module.ts @@ -142,10 +142,10 @@ export class GraphQLFederationModule implements OnModuleInit, OnModuleDestroy { if (!this.httpAdapterHost || !this.httpAdapterHost.httpAdapter) { return; } - const { printSchema } = loadPackage( - '@apollo/federation', + const { printSubgraphSchema } = loadPackage( + '@apollo/subgraph', 'ApolloFederation', - () => require('@apollo/federation'), + () => require('@apollo/subgraph'), ); const { typePaths } = this.options; @@ -161,7 +161,7 @@ export class GraphQLFederationModule implements OnModuleInit, OnModuleDestroy { if (this.options.definitions && this.options.definitions.path) { await this.graphqlFactory.generateDefinitions( - printSchema(apolloOptions.schema), + printSubgraphSchema(apolloOptions.schema), this.options, ); } diff --git a/lib/graphql-definitions.factory.ts b/lib/graphql-definitions.factory.ts index 668642e7a..70eac197f 100644 --- a/lib/graphql-definitions.factory.ts +++ b/lib/graphql-definitions.factory.ts @@ -116,11 +116,16 @@ export class GraphQLDefinitionsFactory { const typePathDefs = await this.gqlTypesLoader.mergeTypesByPaths(typePaths); const mergedTypeDefs = extend(typePathDefs, typeDefs); - const { - buildFederatedSchema, - printSchema, - } = loadPackage('@apollo/federation', 'ApolloFederation', () => - require('@apollo/federation'), + const { buildFederatedSchema } = loadPackage( + '@apollo/federation', + 'ApolloFederation', + () => require('@apollo/federation'), + ); + + const { printSubgraphSchema } = loadPackage( + '@apollo/subgraph', + 'ApolloFederation', + () => require('@apollo/subgraph'), ); const schema = buildFederatedSchema([ @@ -133,7 +138,7 @@ export class GraphQLDefinitionsFactory { ]); const tsFile = await this.gqlAstExplorer.explore( gql` - ${printSchema(schema)} + ${printSubgraphSchema(schema)} `, path, outputAs,