Skip to content

Commit d873051

Browse files
committed
feat: check if is trying to use fed2 without apollo subgraph 2
1 parent 1c1898b commit d873051

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

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

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { mergeSchemas } from '@graphql-tools/schema';
22
import { printSchemaWithDirectives } from '@graphql-tools/utils';
3-
import { Injectable } from '@nestjs/common';
3+
import { Injectable, Logger } from '@nestjs/common';
44
import { loadPackage } from '@nestjs/common/utils/load-package.util';
55
import { isString } from '@nestjs/common/utils/shared.utils';
66
import {
@@ -98,7 +98,7 @@ export class GraphQLFederationFactory {
9898
await import('@apollo/subgraph/package.json')
9999
).version;
100100

101-
const isaApolloSubgraph2 = Number(apolloSubgraphVersion.split('.')[0]) >= 2;
101+
const isApolloSubgraph2 = Number(apolloSubgraphVersion.split('.')[0]) >= 2;
102102
const printSubgraphSchema = apolloSubgraph.printSubgraphSchema;
103103

104104
if (!buildFederatedSchema) {
@@ -110,10 +110,10 @@ export class GraphQLFederationFactory {
110110
options,
111111
this.resolversExplorerService.getAllCtors(),
112112
);
113-
let typeDefs = isaApolloSubgraph2
113+
let typeDefs = isApolloSubgraph2
114114
? printSchemaWithDirectives(autoGeneratedSchema)
115115
: printSubgraphSchema(autoGeneratedSchema);
116-
if (options.useFed2) {
116+
if (options.useFed2 && isApolloSubgraph2) {
117117
const {
118118
directives = [
119119
'@key',
@@ -138,6 +138,11 @@ export class GraphQLFederationFactory {
138138
extend schema @link(url: "${url}", import: [${mappedDirectives}])
139139
${typeDefs}
140140
`;
141+
} else if (options.useFed2 && !isApolloSubgraph2) {
142+
Logger.error(
143+
'You are trying to use Apollo Federation 2 but you are not using @apollo/subgraph@^2.0.0, please upgrade',
144+
'GraphQLFederationFactory',
145+
);
141146
}
142147

143148
let executableSchema: GraphQLSchema = buildFederatedSchema({

0 commit comments

Comments
 (0)