From 20810783f2d3f30b16f76ca95df6f6aa95a26fad Mon Sep 17 00:00:00 2001 From: Chris Lenfest Date: Fri, 12 Jan 2024 12:31:08 -0600 Subject: [PATCH] Bumping join spec and adding federation version 2.7 (#2907) --- .../compose.composeDirective.test.ts.snap | 4 --- composition-js/src/__tests__/compose.test.ts | 24 ++++++------- .../__tests__/gateway/lifecycle-hooks.test.ts | 2 +- internals-js/src/federation.ts | 4 +-- internals-js/src/specs/federationSpec.ts | 8 ++++- internals-js/src/specs/joinSpec.ts | 35 ++++++++++--------- internals-js/src/specs/sourceSpec.ts | 6 +--- internals-js/src/supergraphs.ts | 1 + 8 files changed, 41 insertions(+), 43 deletions(-) diff --git a/composition-js/src/__tests__/__snapshots__/compose.composeDirective.test.ts.snap b/composition-js/src/__tests__/__snapshots__/compose.composeDirective.test.ts.snap index 305e7fa2b..6d651f4ec 100644 --- a/composition-js/src/__tests__/__snapshots__/compose.composeDirective.test.ts.snap +++ b/composition-js/src/__tests__/__snapshots__/compose.composeDirective.test.ts.snap @@ -24,8 +24,6 @@ directive @join__unionMember(graph: join__Graph!, member: String!) repeatable on directive @join__enumValue(graph: join__Graph!) repeatable on ENUM_VALUE -directive @join__directive(graphs: [join__Graph!], name: String!, args: join__DirectiveArguments) repeatable on SCHEMA | OBJECT | INTERFACE | FIELD_DEFINITION - directive @mytag(name: String!) repeatable on FIELD_DEFINITION | OBJECT | INTERFACE | UNION | ARGUMENT_DEFINITION | SCALAR | ENUM | ENUM_VALUE | INPUT_OBJECT | INPUT_FIELD_DEFINITION | SCHEMA directive @tag(name: String!, prop: String!) on FIELD_DEFINITION | OBJECT @@ -51,8 +49,6 @@ enum join__Graph { scalar join__FieldSet -scalar join__DirectiveArguments - type Query @join__type(graph: SUBGRAPHA) @join__type(graph: SUBGRAPHB) diff --git a/composition-js/src/__tests__/compose.test.ts b/composition-js/src/__tests__/compose.test.ts index d5efc9b6e..61c6f53b4 100644 --- a/composition-js/src/__tests__/compose.test.ts +++ b/composition-js/src/__tests__/compose.test.ts @@ -71,7 +71,7 @@ describe('composition', () => { expect(result.supergraphSdl).toMatchString(` schema @link(url: "https://specs.apollo.dev/link/v1.0") - @link(url: "https://specs.apollo.dev/join/v0.3", for: EXECUTION) + @link(url: "https://specs.apollo.dev/join/v0.4", for: EXECUTION) { query: Query } @@ -223,7 +223,7 @@ describe('composition', () => { expect(result.supergraphSdl).toMatchString(` schema @link(url: "https://specs.apollo.dev/link/v1.0") - @link(url: "https://specs.apollo.dev/join/v0.3", for: EXECUTION) + @link(url: "https://specs.apollo.dev/join/v0.4", for: EXECUTION) { query: Query } @@ -2497,8 +2497,6 @@ describe('composition', () => { query: Query } - directive @join__directive(graphs: [join__Graph!], name: String!, args: join__DirectiveArguments) repeatable on SCHEMA | OBJECT | INTERFACE | FIELD_DEFINITION - directive @join__enumValue(graph: join__Graph!) repeatable on ENUM_VALUE directive @join__field(graph: join__Graph, requires: join__FieldSet, provides: join__FieldSet, type: String, external: Boolean, override: String, usedOverridden: Boolean) repeatable on FIELD_DEFINITION | INPUT_FIELD_DEFINITION @@ -2513,8 +2511,6 @@ describe('composition', () => { directive @link(url: String, as: String, for: link__Purpose, import: [link__Import]) repeatable on SCHEMA - scalar join__DirectiveArguments - scalar join__FieldSet enum join__Graph { @@ -4647,7 +4643,7 @@ describe('composition', () => { describe('@source* directives', () => { const schemaA = gql` extend schema - @link(url: "https://specs.apollo.dev/federation/v2.1", import: [ + @link(url: "https://specs.apollo.dev/federation/v2.7", import: [ "@key" "@shareable" ]) @@ -4680,7 +4676,7 @@ describe('@source* directives', () => { const schemaB = gql` extend schema - @link(url: "https://specs.apollo.dev/federation/v2.1", import: [ + @link(url: "https://specs.apollo.dev/federation/v2.7", import: [ "@key" "@shareable" ]) @@ -4708,7 +4704,7 @@ describe('@source* directives', () => { const schemaC = gql` extend schema - @link(url: "https://specs.apollo.dev/federation/v2.1", import: [ + @link(url: "https://specs.apollo.dev/federation/v2.7", import: [ "@key" "@shareable" ]) @@ -4743,7 +4739,7 @@ describe('@source* directives', () => { expect(printed).toContain( `schema @link(url: "https://specs.apollo.dev/link/v1.0") - @link(url: "https://specs.apollo.dev/join/v0.3", for: EXECUTION) + @link(url: "https://specs.apollo.dev/join/v0.4", for: EXECUTION) @join__directive(graphs: [SUBGRAPHA], name: "link", args: {url: "https://specs.apollo.dev/source/v0.1", import: ["@sourceAPI", "@sourceType", "@sourceField"]}) @join__directive(graphs: [SUBGRAPHA], name: "sourceAPI", args: {name: "A", http: {baseURL: "https://api.a.com/v1"}}) { @@ -4790,7 +4786,7 @@ describe('@source* directives', () => { expect(printed).toContain( `schema @link(url: \"https://specs.apollo.dev/link/v1.0\") - @link(url: \"https://specs.apollo.dev/join/v0.3\", for: EXECUTION) + @link(url: \"https://specs.apollo.dev/join/v0.4\", for: EXECUTION) @join__directive(graphs: [SUBGRAPHA, SUBGRAPHB], name: \"link\", args: {url: \"https://specs.apollo.dev/source/v0.1\", import: [\"@sourceAPI\", \"@sourceType\", \"@sourceField\"]}) @join__directive(graphs: [SUBGRAPHA, SUBGRAPHB], name: \"sourceAPI\", args: {name: \"A\", http: {baseURL: \"https://api.a.com/v1\"}}) { @@ -4836,7 +4832,7 @@ describe('@source* directives', () => { expect(printed).toContain( `schema @link(url: \"https://specs.apollo.dev/link/v1.0\") - @link(url: \"https://specs.apollo.dev/join/v0.3\", for: EXECUTION) + @link(url: \"https://specs.apollo.dev/join/v0.4\", for: EXECUTION) @join__directive(graphs: [SUBGRAPHA, SUBGRAPHC], name: \"link\", args: {url: \"https://specs.apollo.dev/source/v0.1\", import: [\"@sourceAPI\", \"@sourceType\", \"@sourceField\"]}) @join__directive(graphs: [SUBGRAPHA, SUBGRAPHC], name: \"sourceAPI\", args: {name: \"A\", http: {baseURL: \"https://api.a.com/v1\"}}) { @@ -4884,7 +4880,7 @@ describe('@source* directives', () => { expect(printed).toContain( `schema @link(url: \"https://specs.apollo.dev/link/v1.0\") - @link(url: \"https://specs.apollo.dev/join/v0.3\", for: EXECUTION) + @link(url: \"https://specs.apollo.dev/join/v0.4\", for: EXECUTION) @join__directive(graphs: [SUBGRAPHB, SUBGRAPHC], name: \"link\", args: {url: \"https://specs.apollo.dev/source/v0.1\", import: [\"@sourceAPI\", \"@sourceType\", \"@sourceField\"]}) @join__directive(graphs: [SUBGRAPHB, SUBGRAPHC], name: \"sourceAPI\", args: {name: \"A\", http: {baseURL: \"https://api.a.com/v1\"}}) { @@ -4933,7 +4929,7 @@ describe('@source* directives', () => { expect(printed).toContain( `schema @link(url: \"https://specs.apollo.dev/link/v1.0\") - @link(url: \"https://specs.apollo.dev/join/v0.3\", for: EXECUTION) + @link(url: \"https://specs.apollo.dev/join/v0.4\", for: EXECUTION) @join__directive(graphs: [SUBGRAPHA, SUBGRAPHB, SUBGRAPHC], name: \"link\", args: {url: \"https://specs.apollo.dev/source/v0.1\", import: [\"@sourceAPI\", \"@sourceType\", \"@sourceField\"]}) @join__directive(graphs: [SUBGRAPHA, SUBGRAPHB, SUBGRAPHC], name: \"sourceAPI\", args: {name: \"A\", http: {baseURL: \"https://api.a.com/v1\"}}) { diff --git a/gateway-js/src/__tests__/gateway/lifecycle-hooks.test.ts b/gateway-js/src/__tests__/gateway/lifecycle-hooks.test.ts index d6b9787ed..b76b6d3c9 100644 --- a/gateway-js/src/__tests__/gateway/lifecycle-hooks.test.ts +++ b/gateway-js/src/__tests__/gateway/lifecycle-hooks.test.ts @@ -149,7 +149,7 @@ describe('lifecycle hooks', () => { // the supergraph (even just formatting differences), this ID will change // and this test will have to updated. expect(secondCall[0]!.compositionId).toEqual( - '4657c2b2d643e1269c49c3f661f5c1e174cef413065c7ab79b28e16ea5f64479', + '2d8ebbf41ff207deab8b6ac5f30f70cb398d5b61d2494f6f28e1c88beddeb49f', ); // second call should have previous info in the second arg expect(secondCall[1]!.compositionId).toEqual(expectedFirstId); diff --git a/internals-js/src/federation.ts b/internals-js/src/federation.ts index 2248803a1..d5af52634 100644 --- a/internals-js/src/federation.ts +++ b/internals-js/src/federation.ts @@ -1221,9 +1221,9 @@ export function setSchemaAsFed2Subgraph(schema: Schema) { // This is the full @link declaration as added by `asFed2SubgraphDocument`. It's here primarily for uses by tests that print and match // subgraph schema to avoid having to update 20+ tests every time we use a new directive or the order of import changes ... -export const FEDERATION2_LINK_WITH_FULL_IMPORTS = '@link(url: "https://specs.apollo.dev/federation/v2.6", import: ["@key", "@requires", "@provides", "@external", "@tag", "@extends", "@shareable", "@inaccessible", "@override", "@composeDirective", "@interfaceObject", "@authenticated", "@requiresScopes", "@policy"])'; +export const FEDERATION2_LINK_WITH_FULL_IMPORTS = '@link(url: "https://specs.apollo.dev/federation/v2.7", import: ["@key", "@requires", "@provides", "@external", "@tag", "@extends", "@shareable", "@inaccessible", "@override", "@composeDirective", "@interfaceObject", "@authenticated", "@requiresScopes", "@policy", "@sourceAPI", "@sourceType", "@sourceField"])'; // This is the full @link declaration that is added when upgrading fed v1 subgraphs to v2 version. It should only be used by tests. -export const FEDERATION2_LINK_WITH_AUTO_EXPANDED_IMPORTS = '@link(url: "https://specs.apollo.dev/federation/v2.6", import: ["@key", "@requires", "@provides", "@external", "@tag", "@extends", "@shareable", "@inaccessible", "@override", "@composeDirective", "@interfaceObject"])'; +export const FEDERATION2_LINK_WITH_AUTO_EXPANDED_IMPORTS = '@link(url: "https://specs.apollo.dev/federation/v2.7", import: ["@key", "@requires", "@provides", "@external", "@tag", "@extends", "@shareable", "@inaccessible", "@override", "@composeDirective", "@interfaceObject"])'; /** * Given a document that is assumed to _not_ be a fed2 schema (it does not have a `@link` to the federation spec), diff --git a/internals-js/src/specs/federationSpec.ts b/internals-js/src/specs/federationSpec.ts index b4df403c0..1fdd8b07a 100644 --- a/internals-js/src/specs/federationSpec.ts +++ b/internals-js/src/specs/federationSpec.ts @@ -18,6 +18,7 @@ import { INACCESSIBLE_VERSIONS } from "./inaccessibleSpec"; import { AUTHENTICATED_VERSIONS } from "./authenticatedSpec"; import { REQUIRES_SCOPES_VERSIONS } from "./requiresScopesSpec"; import { POLICY_VERSIONS } from './policySpec'; +import { SOURCE_VERSIONS } from './sourceSpec'; export const federationIdentity = 'https://specs.apollo.dev/federation'; @@ -158,6 +159,10 @@ export class FederationSpecDefinition extends FeatureDefinition { if (version.gte(new FeatureVersion(2, 6))) { this.registerSubFeature(POLICY_VERSIONS.find(new FeatureVersion(0, 1))!); } + + if (version.gte(new FeatureVersion(2, 7))) { + this.registerSubFeature(SOURCE_VERSIONS.find(new FeatureVersion(0, 1))!); + } } } @@ -168,6 +173,7 @@ export const FEDERATION_VERSIONS = new FeatureDefinitions(joinIdentity) .add(new JoinSpecDefinition(new FeatureVersion(0, 1))) .add(new JoinSpecDefinition(new FeatureVersion(0, 2))) - .add(new JoinSpecDefinition(new FeatureVersion(0, 3), new FeatureVersion(2, 0))); + .add(new JoinSpecDefinition(new FeatureVersion(0, 3), new FeatureVersion(2, 0))) + .add(new JoinSpecDefinition(new FeatureVersion(0, 4), new FeatureVersion(2, 7))); registerKnownFeature(JOIN_VERSIONS); diff --git a/internals-js/src/specs/sourceSpec.ts b/internals-js/src/specs/sourceSpec.ts index b071aba39..78c807318 100644 --- a/internals-js/src/specs/sourceSpec.ts +++ b/internals-js/src/specs/sourceSpec.ts @@ -199,10 +199,6 @@ export type HTTPSourceField = { }; export const SOURCE_VERSIONS = new FeatureDefinitions(sourceIdentity) - .add(new SourceSpecDefinition( - new FeatureVersion(0, 1), - // TODO Expecting this to be bumped to 2.7, but there's no 2.7 version yet. - new FeatureVersion(2, 6), - )); + .add(new SourceSpecDefinition(new FeatureVersion(0, 1), new FeatureVersion(2, 7))); registerKnownFeature(SOURCE_VERSIONS); diff --git a/internals-js/src/supergraphs.ts b/internals-js/src/supergraphs.ts index 3d84fe8f1..ee6fbeadb 100644 --- a/internals-js/src/supergraphs.ts +++ b/internals-js/src/supergraphs.ts @@ -13,6 +13,7 @@ export const DEFAULT_SUPPORTED_SUPERGRAPH_FEATURES = new Set([ 'https://specs.apollo.dev/join/v0.1', 'https://specs.apollo.dev/join/v0.2', 'https://specs.apollo.dev/join/v0.3', + 'https://specs.apollo.dev/join/v0.4', 'https://specs.apollo.dev/tag/v0.1', 'https://specs.apollo.dev/tag/v0.2', 'https://specs.apollo.dev/tag/v0.3',