Skip to content

Commit 6d46d0e

Browse files
committed
fix: check if subgraph is version 2 before generating type defs
1 parent dc10a21 commit 6d46d0e

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

packages/graphql/lib/federation/graphql-federation.factory.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,13 @@ export class GraphQLFederationFactory {
9494
'ApolloFederation',
9595
() => require('@apollo/subgraph'),
9696
);
97+
const apolloSubgraphVersion = loadPackage(
98+
'@apollo/subgraph',
99+
'ApolloFederation',
100+
() => require('@apollo/subgraph/package.json'),
101+
);
97102

103+
const isaApolloSubgraph2 = Number(apolloSubgraphVersion.split('.')[0]) >= 2;
98104
const printSubgraphSchema = apolloSubgraph.printSubgraphSchema;
99105

100106
if (!buildFederatedSchema) {
@@ -106,7 +112,9 @@ export class GraphQLFederationFactory {
106112
options,
107113
this.resolversExplorerService.getAllCtors(),
108114
);
109-
let typeDefs = printSchemaWithDirectives(autoGeneratedSchema);
115+
let typeDefs = isaApolloSubgraph2
116+
? printSchemaWithDirectives(autoGeneratedSchema)
117+
: printSubgraphSchema(autoGeneratedSchema);
110118
if (options.useFed2) {
111119
const {
112120
directives = [

0 commit comments

Comments
 (0)