Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bumping join spec and adding federation version 2.7 #2907

Merged
merged 1 commit into from
Jan 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -51,8 +49,6 @@ enum join__Graph {

scalar join__FieldSet

scalar join__DirectiveArguments

type Query
@join__type(graph: SUBGRAPHA)
@join__type(graph: SUBGRAPHB)
Expand Down
24 changes: 10 additions & 14 deletions composition-js/src/__tests__/compose.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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
Expand All @@ -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 {
Expand Down Expand Up @@ -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"
])
Expand Down Expand Up @@ -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"
])
Expand Down Expand Up @@ -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"
])
Expand Down Expand Up @@ -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"}})
{
Expand Down Expand Up @@ -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\"}})
{
Expand Down Expand Up @@ -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\"}})
{
Expand Down Expand Up @@ -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\"}})
{
Expand Down Expand Up @@ -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\"}})
{
Expand Down
2 changes: 1 addition & 1 deletion gateway-js/src/__tests__/gateway/lifecycle-hooks.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions internals-js/src/federation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
8 changes: 7 additions & 1 deletion internals-js/src/specs/federationSpec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down Expand Up @@ -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))!);
}
}
}

Expand All @@ -168,6 +173,7 @@ export const FEDERATION_VERSIONS = new FeatureDefinitions<FederationSpecDefiniti
.add(new FederationSpecDefinition(new FeatureVersion(2, 3)))
.add(new FederationSpecDefinition(new FeatureVersion(2, 4)))
.add(new FederationSpecDefinition(new FeatureVersion(2, 5)))
.add(new FederationSpecDefinition(new FeatureVersion(2, 6)));
.add(new FederationSpecDefinition(new FeatureVersion(2, 6)))
.add(new FederationSpecDefinition(new FeatureVersion(2, 7)));

registerKnownFeature(FEDERATION_VERSIONS);
35 changes: 19 additions & 16 deletions internals-js/src/specs/joinSpec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -133,21 +133,23 @@ export class JoinSpecDefinition extends FeatureDefinition {
joinEnumValue.addArgument('graph', new NonNullType(graphEnum));
}

const joinDirective = this.addDirective(schema, 'directive').addLocations(
DirectiveLocation.SCHEMA,
DirectiveLocation.OBJECT,
DirectiveLocation.INTERFACE,
DirectiveLocation.FIELD_DEFINITION,
);
joinDirective.repeatable = true;
// Note this 'graphs' argument is plural, since the same directive
// application can appear on the same schema element in multiple subgraphs.
// Repetition of a graph in this 'graphs' list is allowed, and corresponds
// to repeated application of the same directive in the same subgraph, which
// is allowed.
joinDirective.addArgument('graphs', new ListType(new NonNullType(graphEnum)));
joinDirective.addArgument('name', new NonNullType(schema.stringType()));
joinDirective.addArgument('args', this.addScalarType(schema, 'DirectiveArguments'));
if (this.version.gte(new FeatureVersion(0, 4))) {
const joinDirective = this.addDirective(schema, 'directive').addLocations(
DirectiveLocation.SCHEMA,
DirectiveLocation.OBJECT,
DirectiveLocation.INTERFACE,
DirectiveLocation.FIELD_DEFINITION,
);
joinDirective.repeatable = true;
// Note this 'graphs' argument is plural, since the same directive
// application can appear on the same schema element in multiple subgraphs.
// Repetition of a graph in this 'graphs' list is allowed, and corresponds
// to repeated application of the same directive in the same subgraph, which
// is allowed.
joinDirective.addArgument('graphs', new ListType(new NonNullType(graphEnum)));
joinDirective.addArgument('name', new NonNullType(schema.stringType()));
joinDirective.addArgument('args', this.addScalarType(schema, 'DirectiveArguments'));
}

if (this.isV01()) {
const joinOwner = this.addDirective(schema, 'owner').addLocations(DirectiveLocation.OBJECT);
Expand Down Expand Up @@ -257,6 +259,7 @@ export class JoinSpecDefinition extends FeatureDefinition {
export const JOIN_VERSIONS = new FeatureDefinitions<JoinSpecDefinition>(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);
6 changes: 1 addition & 5 deletions internals-js/src/specs/sourceSpec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -199,10 +199,6 @@ export type HTTPSourceField = {
};

export const SOURCE_VERSIONS = new FeatureDefinitions<SourceSpecDefinition>(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);
1 change: 1 addition & 0 deletions internals-js/src/supergraphs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down