|
6 | 6 | HINTS,
|
7 | 7 | } from '../hints';
|
8 | 8 | import { MergeResult, mergeSubgraphs } from '../merging';
|
9 |
| -import { composeAsFed2Subgraphs } from './testHelper'; |
| 9 | +import { assertCompositionSuccess, composeAsFed2Subgraphs } from './testHelper'; |
10 | 10 | import { formatExpectedToMatchReceived } from './matchers/toMatchString';
|
| 11 | +import { composeServices } from '../compose'; |
11 | 12 |
|
12 | 13 | function mergeDocuments(...documents: DocumentNode[]): MergeResult {
|
13 | 14 | const subgraphs = new Subgraphs();
|
@@ -1235,3 +1236,121 @@ describe('when shared field has intersecting but non equal runtime types in diff
|
1235 | 1236 | );
|
1236 | 1237 | });
|
1237 | 1238 | });
|
| 1239 | + |
| 1240 | +describe('when a directive causes an implicit federation version upgrade', () => { |
| 1241 | + const olderFederationSchema = gql` |
| 1242 | + extend schema |
| 1243 | + @link(url: "https://specs.apollo.dev/federation/v2.5", import: ["@key"]) |
| 1244 | +
|
| 1245 | + type Query { |
| 1246 | + a: String! |
| 1247 | + } |
| 1248 | + `; |
| 1249 | + |
| 1250 | + const newerFederationSchema = gql` |
| 1251 | + extend schema |
| 1252 | + @link(url: "https://specs.apollo.dev/federation/v2.7", import: ["@key"]) |
| 1253 | +
|
| 1254 | + type Query { |
| 1255 | + b: String! |
| 1256 | + } |
| 1257 | + `; |
| 1258 | + |
| 1259 | + const autoUpgradedSchema = gql` |
| 1260 | + extend schema |
| 1261 | + @link(url: "https://specs.apollo.dev/federation/v2.5", import: ["@key", "@shareable"]) |
| 1262 | + @link(url: "https://specs.apollo.dev/source/v0.1", import: [ |
| 1263 | + "@sourceAPI" |
| 1264 | + "@sourceType" |
| 1265 | + "@sourceField" |
| 1266 | + ]) |
| 1267 | + @sourceAPI( |
| 1268 | + name: "A" |
| 1269 | + http: { baseURL: "https://api.a.com/v1" } |
| 1270 | + ) |
| 1271 | + { |
| 1272 | + query: Query |
| 1273 | + } |
| 1274 | +
|
| 1275 | + type Query @shareable { |
| 1276 | + resources: [Resource!]! @sourceField( |
| 1277 | + api: "A" |
| 1278 | + http: { GET: "/resources" } |
| 1279 | + ) |
| 1280 | + } |
| 1281 | +
|
| 1282 | + type Resource @shareable @key(fields: "id") @sourceType( |
| 1283 | + api: "A" |
| 1284 | + http: { GET: "/resources/{id}" } |
| 1285 | + selection: "id description" |
| 1286 | + ) { |
| 1287 | + id: ID! |
| 1288 | + description: String! |
| 1289 | + } |
| 1290 | + `; |
| 1291 | + |
| 1292 | + it('should hint that the version was upgraded to satisfy directive requirements', () => { |
| 1293 | + const result = composeServices([ |
| 1294 | + { |
| 1295 | + name: 'already-newest', |
| 1296 | + typeDefs: newerFederationSchema, |
| 1297 | + }, |
| 1298 | + { |
| 1299 | + name: 'old-but-not-upgraded', |
| 1300 | + typeDefs: olderFederationSchema, |
| 1301 | + }, |
| 1302 | + { |
| 1303 | + name: 'upgraded', |
| 1304 | + typeDefs: autoUpgradedSchema, |
| 1305 | + } |
| 1306 | + ]); |
| 1307 | + |
| 1308 | + assertCompositionSuccess(result); |
| 1309 | + expect(result).toRaiseHint( |
| 1310 | + HINTS.IMPLICITLY_UPGRADED_FEDERATION_VERSION, |
| 1311 | + 'Subgraph upgraded has been implicitly upgraded from federation v2.5 to v2.7', |
| 1312 | + '@link' |
| 1313 | + ); |
| 1314 | + }); |
| 1315 | + |
| 1316 | + it('should show separate hints for each upgraded subgraph', () => { |
| 1317 | + const result = composeServices([ |
| 1318 | + { |
| 1319 | + name: 'upgraded-1', |
| 1320 | + typeDefs: autoUpgradedSchema, |
| 1321 | + }, |
| 1322 | + { |
| 1323 | + name: 'upgraded-2', |
| 1324 | + typeDefs: autoUpgradedSchema |
| 1325 | + }, |
| 1326 | + ]); |
| 1327 | + |
| 1328 | + assertCompositionSuccess(result); |
| 1329 | + expect(result).toRaiseHint( |
| 1330 | + HINTS.IMPLICITLY_UPGRADED_FEDERATION_VERSION, |
| 1331 | + 'Subgraph upgraded-1 has been implicitly upgraded from federation v2.5 to v2.7', |
| 1332 | + '@link' |
| 1333 | + ); |
| 1334 | + expect(result).toRaiseHint( |
| 1335 | + HINTS.IMPLICITLY_UPGRADED_FEDERATION_VERSION, |
| 1336 | + 'Subgraph upgraded-2 has been implicitly upgraded from federation v2.5 to v2.7', |
| 1337 | + '@link' |
| 1338 | + ); |
| 1339 | + }); |
| 1340 | + |
| 1341 | + it('should not raise hints if the only upgrade is caused by a link directly to the federation spec', () => { |
| 1342 | + const result = composeServices([ |
| 1343 | + { |
| 1344 | + name: 'already-newest', |
| 1345 | + typeDefs: newerFederationSchema, |
| 1346 | + }, |
| 1347 | + { |
| 1348 | + name: 'old-but-not-upgraded', |
| 1349 | + typeDefs: olderFederationSchema, |
| 1350 | + }, |
| 1351 | + ]); |
| 1352 | + |
| 1353 | + assertCompositionSuccess(result); |
| 1354 | + expect(result).toNotRaiseHints(); |
| 1355 | + }); |
| 1356 | +}) |
0 commit comments