1
1
import { mergeSchemas } from '@graphql-tools/schema' ;
2
2
import { printSchemaWithDirectives } from '@graphql-tools/utils' ;
3
- import { Injectable } from '@nestjs/common' ;
3
+ import { Injectable , Logger } from '@nestjs/common' ;
4
4
import { loadPackage } from '@nestjs/common/utils/load-package.util' ;
5
5
import { isString } from '@nestjs/common/utils/shared.utils' ;
6
6
import {
@@ -98,7 +98,7 @@ export class GraphQLFederationFactory {
98
98
await import ( '@apollo/subgraph/package.json' )
99
99
) . version ;
100
100
101
- const isaApolloSubgraph2 = Number ( apolloSubgraphVersion . split ( '.' ) [ 0 ] ) >= 2 ;
101
+ const isApolloSubgraph2 = Number ( apolloSubgraphVersion . split ( '.' ) [ 0 ] ) >= 2 ;
102
102
const printSubgraphSchema = apolloSubgraph . printSubgraphSchema ;
103
103
104
104
if ( ! buildFederatedSchema ) {
@@ -110,10 +110,10 @@ export class GraphQLFederationFactory {
110
110
options ,
111
111
this . resolversExplorerService . getAllCtors ( ) ,
112
112
) ;
113
- let typeDefs = isaApolloSubgraph2
113
+ let typeDefs = isApolloSubgraph2
114
114
? printSchemaWithDirectives ( autoGeneratedSchema )
115
115
: printSubgraphSchema ( autoGeneratedSchema ) ;
116
- if ( options . useFed2 ) {
116
+ if ( options . useFed2 && isApolloSubgraph2 ) {
117
117
const {
118
118
directives = [
119
119
'@key' ,
@@ -138,6 +138,11 @@ export class GraphQLFederationFactory {
138
138
extend schema @link(url: "${ url } ", import: [${ mappedDirectives } ])
139
139
${ typeDefs }
140
140
` ;
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
+ ) ;
141
146
}
142
147
143
148
let executableSchema : GraphQLSchema = buildFederatedSchema ( {
0 commit comments