From 47469cd6f009e0cf048a0e9e1eaeb698990b9a78 Mon Sep 17 00:00:00 2001 From: Michael Staib Date: Wed, 17 Jan 2024 22:43:54 +0100 Subject: [PATCH 1/5] Fix ApolloFederation FieldSet directives. --- .../Types/Directives/KeyDirective.cs | 14 +++---- .../Directives/KeyLegacySupportAttribute.cs | 2 +- .../Types/Directives/ProvidesDirective.cs | 18 ++++++++- .../Types/Directives/RequiresDirective.cs | 18 ++++++++- .../CertificationTests.Provides.snap | 2 +- .../CertificationTests.Schema_Snapshot.snap | 36 ++++++------------ .../CertificationTests.Subgraph_SDL.snap | 37 +++++++++++++++++-- .../CertificationTests.Schema_Snapshot.snap | 36 ++++++------------ .../CertificationTests.Subgraph_SDL.snap | 37 +++++++++++++++++-- .../ServiceTypeTests.cs | 10 ++--- 10 files changed, 134 insertions(+), 76 deletions(-) diff --git a/src/HotChocolate/ApolloFederation/src/ApolloFederation/Types/Directives/KeyDirective.cs b/src/HotChocolate/ApolloFederation/src/ApolloFederation/Types/Directives/KeyDirective.cs index f220893d6a1..076a7fbce9a 100644 --- a/src/HotChocolate/ApolloFederation/src/ApolloFederation/Types/Directives/KeyDirective.cs +++ b/src/HotChocolate/ApolloFederation/src/ApolloFederation/Types/Directives/KeyDirective.cs @@ -32,22 +32,22 @@ namespace HotChocolate.ApolloFederation.Types; [KeyLegacySupport] public sealed class KeyDirective { - public KeyDirective(string fieldSet, bool resolvable = true) + public KeyDirective(string fields, bool resolvable = true) { - ArgumentException.ThrowIfNullOrEmpty(fieldSet); - FieldSet = FieldSetType.ParseSelectionSet(fieldSet); + ArgumentException.ThrowIfNullOrEmpty(fields); + Fields = FieldSetType.ParseSelectionSet(fields); Resolvable = resolvable; } - public KeyDirective(SelectionSetNode fieldSet, bool resolvable = true) + public KeyDirective(SelectionSetNode fields, bool resolvable = true) { - ArgumentNullException.ThrowIfNull(fieldSet); - FieldSet = fieldSet; + ArgumentNullException.ThrowIfNull(fields); + Fields = fields; Resolvable = resolvable; } [FieldSet] - public SelectionSetNode FieldSet { get; } + public SelectionSetNode Fields { get; } [GraphQLType] [DefaultValue(true)] diff --git a/src/HotChocolate/ApolloFederation/src/ApolloFederation/Types/Directives/KeyLegacySupportAttribute.cs b/src/HotChocolate/ApolloFederation/src/ApolloFederation/Types/Directives/KeyLegacySupportAttribute.cs index 35ce3eaf50c..8aa10f9d292 100644 --- a/src/HotChocolate/ApolloFederation/src/ApolloFederation/Types/Directives/KeyLegacySupportAttribute.cs +++ b/src/HotChocolate/ApolloFederation/src/ApolloFederation/Types/Directives/KeyLegacySupportAttribute.cs @@ -13,7 +13,7 @@ protected override void OnConfigure( { var desc = (IDirectiveTypeDescriptor)descriptor; desc.BindArgumentsExplicitly(); - desc.Argument(t => t.FieldSet); + desc.Argument(t => t.Fields); } } } \ No newline at end of file diff --git a/src/HotChocolate/ApolloFederation/src/ApolloFederation/Types/Directives/ProvidesDirective.cs b/src/HotChocolate/ApolloFederation/src/ApolloFederation/Types/Directives/ProvidesDirective.cs index 6812dc046a0..99a6af13178 100644 --- a/src/HotChocolate/ApolloFederation/src/ApolloFederation/Types/Directives/ProvidesDirective.cs +++ b/src/HotChocolate/ApolloFederation/src/ApolloFederation/Types/Directives/ProvidesDirective.cs @@ -1,6 +1,8 @@ +using HotChocolate.Language; using static HotChocolate.ApolloFederation.FederationTypeNames; using static HotChocolate.ApolloFederation.FederationVersionUrls; using static HotChocolate.ApolloFederation.Properties.FederationResources; +using DirectiveLocation = HotChocolate.Types.DirectiveLocation; namespace HotChocolate.ApolloFederation.Types; @@ -34,8 +36,20 @@ namespace HotChocolate.ApolloFederation.Types; [Package(Federation20)] [DirectiveType(ProvidesDirective_Name, DirectiveLocation.FieldDefinition)] [GraphQLDescription(ProvidesDirective_Description)] -public sealed class ProvidesDirective(string fieldSet) +public sealed class ProvidesDirective { + public ProvidesDirective(string fields) + { + ArgumentException.ThrowIfNullOrEmpty(fields); + Fields = FieldSetType.ParseSelectionSet(fields); + } + + public ProvidesDirective(SelectionSetNode fields) + { + ArgumentNullException.ThrowIfNull(fields); + Fields = fields; + } + [FieldSet] - public string FieldSet { get; } = fieldSet; + public SelectionSetNode Fields { get; } } diff --git a/src/HotChocolate/ApolloFederation/src/ApolloFederation/Types/Directives/RequiresDirective.cs b/src/HotChocolate/ApolloFederation/src/ApolloFederation/Types/Directives/RequiresDirective.cs index 277b4bdf090..c6b66e1bfc2 100644 --- a/src/HotChocolate/ApolloFederation/src/ApolloFederation/Types/Directives/RequiresDirective.cs +++ b/src/HotChocolate/ApolloFederation/src/ApolloFederation/Types/Directives/RequiresDirective.cs @@ -1,6 +1,8 @@ +using HotChocolate.Language; using static HotChocolate.ApolloFederation.FederationTypeNames; using static HotChocolate.ApolloFederation.FederationVersionUrls; using static HotChocolate.ApolloFederation.Properties.FederationResources; +using DirectiveLocation = HotChocolate.Types.DirectiveLocation; namespace HotChocolate.ApolloFederation.Types; @@ -27,8 +29,20 @@ namespace HotChocolate.ApolloFederation.Types; [Package(Federation20)] [DirectiveType(RequiresDirective_Name, DirectiveLocation.FieldDefinition)] [GraphQLDescription(RequiresDirective_Description)] -public sealed class RequiresDirective(string fieldSet) +public sealed class RequiresDirective { + public RequiresDirective(string fields) + { + ArgumentException.ThrowIfNullOrEmpty(fields); + Fields = FieldSetType.ParseSelectionSet(fields); + } + + public RequiresDirective(SelectionSetNode fields) + { + ArgumentNullException.ThrowIfNull(fields); + Fields = fields; + } + [FieldSet] - public string FieldSet { get; } = fieldSet; + public SelectionSetNode Fields { get; } } \ No newline at end of file diff --git a/src/HotChocolate/ApolloFederation/test/ApolloFederation.Tests/CertificationSchema/AnnotationBased/__snapshots__/CertificationTests.Provides.snap b/src/HotChocolate/ApolloFederation/test/ApolloFederation.Tests/CertificationSchema/AnnotationBased/__snapshots__/CertificationTests.Provides.snap index c3dffea86c6..9e20d556c67 100644 --- a/src/HotChocolate/ApolloFederation/test/ApolloFederation.Tests/CertificationSchema/AnnotationBased/__snapshots__/CertificationTests.Provides.snap +++ b/src/HotChocolate/ApolloFederation/test/ApolloFederation.Tests/CertificationSchema/AnnotationBased/__snapshots__/CertificationTests.Provides.snap @@ -2,7 +2,7 @@ "data": { "product": { "createdBy": { - "email": "support@apollographql.com", + "email": "contact@chillicream.com", "totalProductsCreated": 1337 } } diff --git a/src/HotChocolate/ApolloFederation/test/ApolloFederation.Tests/CertificationSchema/AnnotationBased/__snapshots__/CertificationTests.Schema_Snapshot.snap b/src/HotChocolate/ApolloFederation/test/ApolloFederation.Tests/CertificationSchema/AnnotationBased/__snapshots__/CertificationTests.Schema_Snapshot.snap index 37373d1113d..5c9c99ab5ba 100644 --- a/src/HotChocolate/ApolloFederation/test/ApolloFederation.Tests/CertificationSchema/AnnotationBased/__snapshots__/CertificationTests.Schema_Snapshot.snap +++ b/src/HotChocolate/ApolloFederation/test/ApolloFederation.Tests/CertificationSchema/AnnotationBased/__snapshots__/CertificationTests.Schema_Snapshot.snap @@ -1,4 +1,4 @@ -schema @link(url: "https:\/\/specs.apollo.dev\/federation\/v2.5", import: [ "@extends", "@external", "@key", "@inaccessible", "@override", "@provides", "@requires", "@shareable", "@tag", "FieldSet", "@composeDirective", "@interfaceObject", "@authenticated", "@requiresPolicy" ]) { +schema @link(url: "https:\/\/specs.apollo.dev\/federation\/v2.0", import: [ "@extends", "@key", "@provides", "FieldSet", "@external" ]) { query: Query } @@ -20,13 +20,13 @@ type ProductVariation { id: ID! } -type Query { +type Query @extends { product(id: ID!): Product - _service: _Service! + _service: _Service _entities(representations: [_Any!]!): [_Entity]! } -type User @key(fields: "email") { +type User @key(fields: "email") @extends { email: ID! @external totalProductsCreated: Int @external } @@ -39,37 +39,23 @@ type _Service { "Union of all types that key directive applied. This information is needed by the Apollo federation gateway." union _Entity = Product | User -"Indicates to composition that the target element is accessible only to the authenticated supergraph users." -directive @authenticated on SCALAR | OBJECT | FIELD_DEFINITION | INTERFACE | ENUM - -"Marks underlying custom directive to be included in the Supergraph schema." -directive @composeDirective(name: String!) on SCHEMA - "Directive to indicate that marks target object as extending part of the federated schema." directive @extends on OBJECT | INTERFACE "Directive to indicate that a field is owned by another service, for example via Apollo federation." directive @external on FIELD_DEFINITION -"Marks location within schema as inaccessible from the GraphQL Gateway" -directive @inaccessible on SCALAR | OBJECT | FIELD_DEFINITION | ARGUMENT_DEFINITION | INTERFACE | UNION | ENUM | ENUM_VALUE | INPUT_OBJECT | INPUT_FIELD_DEFINITION - -"Provides meta information to the router that this entity type is an interface in the supergraph." -directive @interfaceObject on OBJECT - "Used to indicate a combination of fields that can be used to uniquely identify and fetch an object or interface." -directive @key(fields: _FieldSet! resolvable: Boolean = true) repeatable on OBJECT | INTERFACE - -directive @link(url: String! import: [String!]) repeatable on SCHEMA +directive @key(fields: FieldSet! resolvable: Boolean = true) repeatable on OBJECT | INTERFACE -"Overrides fields resolution logic from other subgraph. Used for migrating fields from one subgraph to another." -directive @override(from: String!) on FIELD_DEFINITION +"Object representation of @link directive." +directive @link("Gets imported specification url." url: String! "Gets optional list of imported element names." import: [String!]) repeatable on SCHEMA "Used to annotate the expected returned fieldset from a field on a base type that is guaranteed to be selectable by the federation gateway." -directive @provides(fields: _FieldSet!) on FIELD_DEFINITION +directive @provides(fields: FieldSet!) on FIELD_DEFINITION + +"Scalar representing a set of fields." +scalar FieldSet "The _Any scalar is used to pass representations of entities from external services into the root _entities field for execution. Validation of the _Any scalar is done by matching the __typename and @external fields defined in the schema." scalar _Any - -"Scalar representing a set of fields." -scalar _FieldSet diff --git a/src/HotChocolate/ApolloFederation/test/ApolloFederation.Tests/CertificationSchema/AnnotationBased/__snapshots__/CertificationTests.Subgraph_SDL.snap b/src/HotChocolate/ApolloFederation/test/ApolloFederation.Tests/CertificationSchema/AnnotationBased/__snapshots__/CertificationTests.Subgraph_SDL.snap index 12e452e23a7..5c9c99ab5ba 100644 --- a/src/HotChocolate/ApolloFederation/test/ApolloFederation.Tests/CertificationSchema/AnnotationBased/__snapshots__/CertificationTests.Subgraph_SDL.snap +++ b/src/HotChocolate/ApolloFederation/test/ApolloFederation.Tests/CertificationSchema/AnnotationBased/__snapshots__/CertificationTests.Subgraph_SDL.snap @@ -1,4 +1,4 @@ -schema @link(url: "https:\/\/specs.apollo.dev\/federation\/v2.5", import: [ "@extends", "@external", "@key", "@inaccessible", "@override", "@provides", "@requires", "@shareable", "@tag", "FieldSet", "@composeDirective", "@interfaceObject", "@authenticated", "@requiresPolicy" ]) { +schema @link(url: "https:\/\/specs.apollo.dev\/federation\/v2.0", import: [ "@extends", "@key", "@provides", "FieldSet", "@external" ]) { query: Query } @@ -20,13 +20,42 @@ type ProductVariation { id: ID! } -type Query { +type Query @extends { product(id: ID!): Product - _service: _Service! + _service: _Service _entities(representations: [_Any!]!): [_Entity]! } -type User @key(fields: "email") { +type User @key(fields: "email") @extends { email: ID! @external totalProductsCreated: Int @external } + +"This type provides a field named sdl: String! which exposes the SDL of the service's schema. This SDL (schema definition language) is a printed version of the service's schema including the annotations of federation directives. This SDL does not include the additions of the federation spec." +type _Service { + sdl: String! +} + +"Union of all types that key directive applied. This information is needed by the Apollo federation gateway." +union _Entity = Product | User + +"Directive to indicate that marks target object as extending part of the federated schema." +directive @extends on OBJECT | INTERFACE + +"Directive to indicate that a field is owned by another service, for example via Apollo federation." +directive @external on FIELD_DEFINITION + +"Used to indicate a combination of fields that can be used to uniquely identify and fetch an object or interface." +directive @key(fields: FieldSet! resolvable: Boolean = true) repeatable on OBJECT | INTERFACE + +"Object representation of @link directive." +directive @link("Gets imported specification url." url: String! "Gets optional list of imported element names." import: [String!]) repeatable on SCHEMA + +"Used to annotate the expected returned fieldset from a field on a base type that is guaranteed to be selectable by the federation gateway." +directive @provides(fields: FieldSet!) on FIELD_DEFINITION + +"Scalar representing a set of fields." +scalar FieldSet + +"The _Any scalar is used to pass representations of entities from external services into the root _entities field for execution. Validation of the _Any scalar is done by matching the __typename and @external fields defined in the schema." +scalar _Any diff --git a/src/HotChocolate/ApolloFederation/test/ApolloFederation.Tests/CertificationSchema/CodeFirst/__snapshots__/CertificationTests.Schema_Snapshot.snap b/src/HotChocolate/ApolloFederation/test/ApolloFederation.Tests/CertificationSchema/CodeFirst/__snapshots__/CertificationTests.Schema_Snapshot.snap index 274b33f4b15..459e3d57aa7 100644 --- a/src/HotChocolate/ApolloFederation/test/ApolloFederation.Tests/CertificationSchema/CodeFirst/__snapshots__/CertificationTests.Schema_Snapshot.snap +++ b/src/HotChocolate/ApolloFederation/test/ApolloFederation.Tests/CertificationSchema/CodeFirst/__snapshots__/CertificationTests.Schema_Snapshot.snap @@ -1,4 +1,4 @@ -schema @link(url: "https:\/\/specs.apollo.dev\/federation\/v2.5", import: [ "@extends", "@external", "@key", "@inaccessible", "@override", "@provides", "@requires", "@shareable", "@tag", "FieldSet", "@composeDirective", "@interfaceObject", "@authenticated", "@requiresPolicy" ]) { +schema @link(url: "https:\/\/specs.apollo.dev\/federation\/v2.0", import: [ "@extends", "@key", "@provides", "@external", "FieldSet" ]) { query: Query } @@ -20,13 +20,13 @@ type ProductVariation { id: ID! } -type Query { +type Query @extends { product(id: ID!): Product - _service: _Service! + _service: _Service _entities(representations: [_Any!]!): [_Entity]! } -type User @key(fields: "email") { +type User @extends @key(fields: "email") { email: ID! @external totalProductsCreated: Int @external } @@ -39,37 +39,23 @@ type _Service { "Union of all types that key directive applied. This information is needed by the Apollo federation gateway." union _Entity = Product | User -"Indicates to composition that the target element is accessible only to the authenticated supergraph users." -directive @authenticated on SCALAR | OBJECT | FIELD_DEFINITION | INTERFACE | ENUM - -"Marks underlying custom directive to be included in the Supergraph schema." -directive @composeDirective(name: String!) on SCHEMA - "Directive to indicate that marks target object as extending part of the federated schema." directive @extends on OBJECT | INTERFACE "Directive to indicate that a field is owned by another service, for example via Apollo federation." directive @external on FIELD_DEFINITION -"Marks location within schema as inaccessible from the GraphQL Gateway" -directive @inaccessible on SCALAR | OBJECT | FIELD_DEFINITION | ARGUMENT_DEFINITION | INTERFACE | UNION | ENUM | ENUM_VALUE | INPUT_OBJECT | INPUT_FIELD_DEFINITION - -"Provides meta information to the router that this entity type is an interface in the supergraph." -directive @interfaceObject on OBJECT - "Used to indicate a combination of fields that can be used to uniquely identify and fetch an object or interface." -directive @key(fields: _FieldSet! resolvable: Boolean = true) repeatable on OBJECT | INTERFACE - -directive @link(url: String! import: [String!]) repeatable on SCHEMA +directive @key(fields: FieldSet! resolvable: Boolean = true) repeatable on OBJECT | INTERFACE -"Overrides fields resolution logic from other subgraph. Used for migrating fields from one subgraph to another." -directive @override(from: String!) on FIELD_DEFINITION +"Object representation of @link directive." +directive @link("Gets imported specification url." url: String! "Gets optional list of imported element names." import: [String!]) repeatable on SCHEMA "Used to annotate the expected returned fieldset from a field on a base type that is guaranteed to be selectable by the federation gateway." -directive @provides(fields: _FieldSet!) on FIELD_DEFINITION +directive @provides(fields: FieldSet!) on FIELD_DEFINITION + +"Scalar representing a set of fields." +scalar FieldSet "The _Any scalar is used to pass representations of entities from external services into the root _entities field for execution. Validation of the _Any scalar is done by matching the __typename and @external fields defined in the schema." scalar _Any - -"Scalar representing a set of fields." -scalar _FieldSet diff --git a/src/HotChocolate/ApolloFederation/test/ApolloFederation.Tests/CertificationSchema/CodeFirst/__snapshots__/CertificationTests.Subgraph_SDL.snap b/src/HotChocolate/ApolloFederation/test/ApolloFederation.Tests/CertificationSchema/CodeFirst/__snapshots__/CertificationTests.Subgraph_SDL.snap index 105bbab3e47..459e3d57aa7 100644 --- a/src/HotChocolate/ApolloFederation/test/ApolloFederation.Tests/CertificationSchema/CodeFirst/__snapshots__/CertificationTests.Subgraph_SDL.snap +++ b/src/HotChocolate/ApolloFederation/test/ApolloFederation.Tests/CertificationSchema/CodeFirst/__snapshots__/CertificationTests.Subgraph_SDL.snap @@ -1,4 +1,4 @@ -schema @link(url: "https:\/\/specs.apollo.dev\/federation\/v2.5", import: [ "@extends", "@external", "@key", "@inaccessible", "@override", "@provides", "@requires", "@shareable", "@tag", "FieldSet", "@composeDirective", "@interfaceObject", "@authenticated", "@requiresPolicy" ]) { +schema @link(url: "https:\/\/specs.apollo.dev\/federation\/v2.0", import: [ "@extends", "@key", "@provides", "@external", "FieldSet" ]) { query: Query } @@ -20,13 +20,42 @@ type ProductVariation { id: ID! } -type Query { +type Query @extends { product(id: ID!): Product - _service: _Service! + _service: _Service _entities(representations: [_Any!]!): [_Entity]! } -type User @key(fields: "email") { +type User @extends @key(fields: "email") { email: ID! @external totalProductsCreated: Int @external } + +"This type provides a field named sdl: String! which exposes the SDL of the service's schema. This SDL (schema definition language) is a printed version of the service's schema including the annotations of federation directives. This SDL does not include the additions of the federation spec." +type _Service { + sdl: String! +} + +"Union of all types that key directive applied. This information is needed by the Apollo federation gateway." +union _Entity = Product | User + +"Directive to indicate that marks target object as extending part of the federated schema." +directive @extends on OBJECT | INTERFACE + +"Directive to indicate that a field is owned by another service, for example via Apollo federation." +directive @external on FIELD_DEFINITION + +"Used to indicate a combination of fields that can be used to uniquely identify and fetch an object or interface." +directive @key(fields: FieldSet! resolvable: Boolean = true) repeatable on OBJECT | INTERFACE + +"Object representation of @link directive." +directive @link("Gets imported specification url." url: String! "Gets optional list of imported element names." import: [String!]) repeatable on SCHEMA + +"Used to annotate the expected returned fieldset from a field on a base type that is guaranteed to be selectable by the federation gateway." +directive @provides(fields: FieldSet!) on FIELD_DEFINITION + +"Scalar representing a set of fields." +scalar FieldSet + +"The _Any scalar is used to pass representations of entities from external services into the root _entities field for execution. Validation of the _Any scalar is done by matching the __typename and @external fields defined in the schema." +scalar _Any diff --git a/src/HotChocolate/ApolloFederation/test/ApolloFederation.Tests/ServiceTypeTests.cs b/src/HotChocolate/ApolloFederation/test/ApolloFederation.Tests/ServiceTypeTests.cs index 8d772634ef6..4ca015eee20 100644 --- a/src/HotChocolate/ApolloFederation/test/ApolloFederation.Tests/ServiceTypeTests.cs +++ b/src/HotChocolate/ApolloFederation/test/ApolloFederation.Tests/ServiceTypeTests.cs @@ -39,7 +39,7 @@ schema @link(url: "https:\/\/specs.apollo.dev\/federation\/v2.0", import: [ "@ke query: Query } - type Address @key(fieldSet: "matchCode") { + type Address @key(fields: "matchCode") { matchCode: String } @@ -57,7 +57,7 @@ type _Service { union _Entity = Address "Used to indicate a combination of fields that can be used to uniquely identify and fetch an object or interface." - directive @key(fieldSet: FieldSet! resolvable: Boolean = true) repeatable on OBJECT | INTERFACE + directive @key(fields: FieldSet! resolvable: Boolean = true) repeatable on OBJECT | INTERFACE "Object representation of @link directive." directive @link("Gets imported specification url." url: String! "Gets optional list of imported element names." import: [String!]) repeatable on SCHEMA @@ -76,7 +76,7 @@ public async Task TestServiceTypeTypePureCodeFirst() // arrange var schema = await new ServiceCollection() .AddGraphQL() - .AddApolloFederation() + .AddApolloFederation(FederationVersion.Federation22) .AddQueryType() .BuildSchemaAsync(); @@ -95,7 +95,7 @@ schema @link(url: "https:\/\/specs.apollo.dev\/federation\/v2.0", import: [ "@ke query: Query } - type Address @key(fieldSet: "matchCode") { + type Address @key(fields: "matchCode") { matchCode: String } @@ -114,7 +114,7 @@ type _Service { union _Entity = Address "Used to indicate a combination of fields that can be used to uniquely identify and fetch an object or interface." - directive @key(fieldSet: FieldSet! resolvable: Boolean = true) repeatable on OBJECT | INTERFACE + directive @key(fields: FieldSet! resolvable: Boolean = true) repeatable on OBJECT | INTERFACE "Object representation of @link directive." directive @link("Gets imported specification url." url: String! "Gets optional list of imported element names." import: [String!]) repeatable on SCHEMA From 424c79f9f39594d7c4ccb10e7343a209e7dbb5b3 Mon Sep 17 00:00:00 2001 From: Michael Staib Date: Wed, 17 Jan 2024 22:51:17 +0100 Subject: [PATCH 2/5] edits --- .../src/ApolloFederation/FederationTypeInterceptor.cs | 2 -- .../src/ApolloFederation/Types/ServerFields.cs | 2 +- .../__snapshots__/CertificationTests.Schema_Snapshot.snap | 2 +- .../__snapshots__/CertificationTests.Subgraph_SDL.snap | 2 +- .../__snapshots__/CertificationTests.Schema_Snapshot.snap | 2 +- .../__snapshots__/CertificationTests.Subgraph_SDL.snap | 2 +- .../test/ApolloFederation.Tests/ServiceTypeTests.cs | 4 ++-- 7 files changed, 7 insertions(+), 9 deletions(-) diff --git a/src/HotChocolate/ApolloFederation/src/ApolloFederation/FederationTypeInterceptor.cs b/src/HotChocolate/ApolloFederation/src/ApolloFederation/FederationTypeInterceptor.cs index 688f1079b7d..4253eae3194 100644 --- a/src/HotChocolate/ApolloFederation/src/ApolloFederation/FederationTypeInterceptor.cs +++ b/src/HotChocolate/ApolloFederation/src/ApolloFederation/FederationTypeInterceptor.cs @@ -102,9 +102,7 @@ public override IEnumerable RegisterMoreTypes( yield return _typeInspector.GetTypeRef(typeof(LinkDirective)); } } - - public override void OnBeforeCompleteName( ITypeCompletionContext completionContext, DefinitionBase definition) diff --git a/src/HotChocolate/ApolloFederation/src/ApolloFederation/Types/ServerFields.cs b/src/HotChocolate/ApolloFederation/src/ApolloFederation/Types/ServerFields.cs index 83e27885dc5..dedd00a5301 100644 --- a/src/HotChocolate/ApolloFederation/src/ApolloFederation/Types/ServerFields.cs +++ b/src/HotChocolate/ApolloFederation/src/ApolloFederation/Types/ServerFields.cs @@ -17,7 +17,7 @@ public static class ServerFields internal static ObjectFieldDefinition CreateServiceField(IDescriptorContext context) { var descriptor = ObjectFieldDescriptor.New(context, WellKnownFieldNames.Service); - descriptor.Resolve(_service); + descriptor.Type>>().Resolve(_service); descriptor.Definition.PureResolver = Resolve; static _Service Resolve(IPureResolverContext ctx) diff --git a/src/HotChocolate/ApolloFederation/test/ApolloFederation.Tests/CertificationSchema/AnnotationBased/__snapshots__/CertificationTests.Schema_Snapshot.snap b/src/HotChocolate/ApolloFederation/test/ApolloFederation.Tests/CertificationSchema/AnnotationBased/__snapshots__/CertificationTests.Schema_Snapshot.snap index 5c9c99ab5ba..c3e4cb2890b 100644 --- a/src/HotChocolate/ApolloFederation/test/ApolloFederation.Tests/CertificationSchema/AnnotationBased/__snapshots__/CertificationTests.Schema_Snapshot.snap +++ b/src/HotChocolate/ApolloFederation/test/ApolloFederation.Tests/CertificationSchema/AnnotationBased/__snapshots__/CertificationTests.Schema_Snapshot.snap @@ -22,7 +22,7 @@ type ProductVariation { type Query @extends { product(id: ID!): Product - _service: _Service + _service: _Service! _entities(representations: [_Any!]!): [_Entity]! } diff --git a/src/HotChocolate/ApolloFederation/test/ApolloFederation.Tests/CertificationSchema/AnnotationBased/__snapshots__/CertificationTests.Subgraph_SDL.snap b/src/HotChocolate/ApolloFederation/test/ApolloFederation.Tests/CertificationSchema/AnnotationBased/__snapshots__/CertificationTests.Subgraph_SDL.snap index 5c9c99ab5ba..c3e4cb2890b 100644 --- a/src/HotChocolate/ApolloFederation/test/ApolloFederation.Tests/CertificationSchema/AnnotationBased/__snapshots__/CertificationTests.Subgraph_SDL.snap +++ b/src/HotChocolate/ApolloFederation/test/ApolloFederation.Tests/CertificationSchema/AnnotationBased/__snapshots__/CertificationTests.Subgraph_SDL.snap @@ -22,7 +22,7 @@ type ProductVariation { type Query @extends { product(id: ID!): Product - _service: _Service + _service: _Service! _entities(representations: [_Any!]!): [_Entity]! } diff --git a/src/HotChocolate/ApolloFederation/test/ApolloFederation.Tests/CertificationSchema/CodeFirst/__snapshots__/CertificationTests.Schema_Snapshot.snap b/src/HotChocolate/ApolloFederation/test/ApolloFederation.Tests/CertificationSchema/CodeFirst/__snapshots__/CertificationTests.Schema_Snapshot.snap index 459e3d57aa7..3fde4975778 100644 --- a/src/HotChocolate/ApolloFederation/test/ApolloFederation.Tests/CertificationSchema/CodeFirst/__snapshots__/CertificationTests.Schema_Snapshot.snap +++ b/src/HotChocolate/ApolloFederation/test/ApolloFederation.Tests/CertificationSchema/CodeFirst/__snapshots__/CertificationTests.Schema_Snapshot.snap @@ -22,7 +22,7 @@ type ProductVariation { type Query @extends { product(id: ID!): Product - _service: _Service + _service: _Service! _entities(representations: [_Any!]!): [_Entity]! } diff --git a/src/HotChocolate/ApolloFederation/test/ApolloFederation.Tests/CertificationSchema/CodeFirst/__snapshots__/CertificationTests.Subgraph_SDL.snap b/src/HotChocolate/ApolloFederation/test/ApolloFederation.Tests/CertificationSchema/CodeFirst/__snapshots__/CertificationTests.Subgraph_SDL.snap index 459e3d57aa7..3fde4975778 100644 --- a/src/HotChocolate/ApolloFederation/test/ApolloFederation.Tests/CertificationSchema/CodeFirst/__snapshots__/CertificationTests.Subgraph_SDL.snap +++ b/src/HotChocolate/ApolloFederation/test/ApolloFederation.Tests/CertificationSchema/CodeFirst/__snapshots__/CertificationTests.Subgraph_SDL.snap @@ -22,7 +22,7 @@ type ProductVariation { type Query @extends { product(id: ID!): Product - _service: _Service + _service: _Service! _entities(representations: [_Any!]!): [_Entity]! } diff --git a/src/HotChocolate/ApolloFederation/test/ApolloFederation.Tests/ServiceTypeTests.cs b/src/HotChocolate/ApolloFederation/test/ApolloFederation.Tests/ServiceTypeTests.cs index 4ca015eee20..c4cb386ba3c 100644 --- a/src/HotChocolate/ApolloFederation/test/ApolloFederation.Tests/ServiceTypeTests.cs +++ b/src/HotChocolate/ApolloFederation/test/ApolloFederation.Tests/ServiceTypeTests.cs @@ -44,7 +44,7 @@ type Address @key(fields: "matchCode") { } type Query { - _service: _Service + _service: _Service! _entities(representations: [_Any!]!): [_Entity]! } @@ -101,7 +101,7 @@ type Address @key(fields: "matchCode") { type Query { address(id: Int!): Address! - _service: _Service + _service: _Service! _entities(representations: [_Any!]!): [_Entity]! } From 50203fb0253da5b278d3214a17510bdd359eb5e5 Mon Sep 17 00:00:00 2001 From: Michael Staib Date: Wed, 17 Jan 2024 22:53:55 +0100 Subject: [PATCH 3/5] edits --- .../Directives/ExtendServiceTypeDescriptorExtensions.cs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/HotChocolate/ApolloFederation/src/ApolloFederation/Types/Directives/ExtendServiceTypeDescriptorExtensions.cs b/src/HotChocolate/ApolloFederation/src/ApolloFederation/Types/Directives/ExtendServiceTypeDescriptorExtensions.cs index 9903a763265..be4df8fda36 100644 --- a/src/HotChocolate/ApolloFederation/src/ApolloFederation/Types/Directives/ExtendServiceTypeDescriptorExtensions.cs +++ b/src/HotChocolate/ApolloFederation/src/ApolloFederation/Types/Directives/ExtendServiceTypeDescriptorExtensions.cs @@ -62,7 +62,11 @@ public static IObjectTypeDescriptor ExtendServiceType( { ArgumentNullException.ThrowIfNull(descriptor); - descriptor.Directive(ExtendServiceTypeDirective.Default); + if (descriptor.Extend().Context.GetFederationVersion() == FederationVersion.Federation10) + { + descriptor.Directive(ExtendServiceTypeDirective.Default); + } + return descriptor; } } \ No newline at end of file From 6b4edfcf911c2ea73a44bb3fcc2b541f2381ae5a Mon Sep 17 00:00:00 2001 From: Michael Staib Date: Wed, 17 Jan 2024 22:54:56 +0100 Subject: [PATCH 4/5] edits --- .../Directives/ExtendServiceTypeDescriptorExtensions.cs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/HotChocolate/ApolloFederation/src/ApolloFederation/Types/Directives/ExtendServiceTypeDescriptorExtensions.cs b/src/HotChocolate/ApolloFederation/src/ApolloFederation/Types/Directives/ExtendServiceTypeDescriptorExtensions.cs index be4df8fda36..5c367a91ab5 100644 --- a/src/HotChocolate/ApolloFederation/src/ApolloFederation/Types/Directives/ExtendServiceTypeDescriptorExtensions.cs +++ b/src/HotChocolate/ApolloFederation/src/ApolloFederation/Types/Directives/ExtendServiceTypeDescriptorExtensions.cs @@ -30,7 +30,11 @@ public static IObjectTypeDescriptor ExtendServiceType( { ArgumentNullException.ThrowIfNull(descriptor); - descriptor.Directive(ExtendServiceTypeDirective.Default); + if (descriptor.Extend().Context.GetFederationVersion() == FederationVersion.Federation10) + { + descriptor.Directive(ExtendServiceTypeDirective.Default); + } + return descriptor; } From fa67b7ff11d367f232e1788ebff86c188bc40969 Mon Sep 17 00:00:00 2001 From: Michael Staib Date: Wed, 17 Jan 2024 22:55:54 +0100 Subject: [PATCH 5/5] edits --- .../CertificationTests.Schema_Snapshot.snap | 9 +++------ .../__snapshots__/CertificationTests.Subgraph_SDL.snap | 9 +++------ .../CertificationTests.Schema_Snapshot.snap | 9 +++------ .../__snapshots__/CertificationTests.Subgraph_SDL.snap | 9 +++------ 4 files changed, 12 insertions(+), 24 deletions(-) diff --git a/src/HotChocolate/ApolloFederation/test/ApolloFederation.Tests/CertificationSchema/AnnotationBased/__snapshots__/CertificationTests.Schema_Snapshot.snap b/src/HotChocolate/ApolloFederation/test/ApolloFederation.Tests/CertificationSchema/AnnotationBased/__snapshots__/CertificationTests.Schema_Snapshot.snap index c3e4cb2890b..5430dbe40ec 100644 --- a/src/HotChocolate/ApolloFederation/test/ApolloFederation.Tests/CertificationSchema/AnnotationBased/__snapshots__/CertificationTests.Schema_Snapshot.snap +++ b/src/HotChocolate/ApolloFederation/test/ApolloFederation.Tests/CertificationSchema/AnnotationBased/__snapshots__/CertificationTests.Schema_Snapshot.snap @@ -1,4 +1,4 @@ -schema @link(url: "https:\/\/specs.apollo.dev\/federation\/v2.0", import: [ "@extends", "@key", "@provides", "FieldSet", "@external" ]) { +schema @link(url: "https:\/\/specs.apollo.dev\/federation\/v2.0", import: [ "@key", "@provides", "FieldSet", "@external" ]) { query: Query } @@ -20,13 +20,13 @@ type ProductVariation { id: ID! } -type Query @extends { +type Query { product(id: ID!): Product _service: _Service! _entities(representations: [_Any!]!): [_Entity]! } -type User @key(fields: "email") @extends { +type User @key(fields: "email") { email: ID! @external totalProductsCreated: Int @external } @@ -39,9 +39,6 @@ type _Service { "Union of all types that key directive applied. This information is needed by the Apollo federation gateway." union _Entity = Product | User -"Directive to indicate that marks target object as extending part of the federated schema." -directive @extends on OBJECT | INTERFACE - "Directive to indicate that a field is owned by another service, for example via Apollo federation." directive @external on FIELD_DEFINITION diff --git a/src/HotChocolate/ApolloFederation/test/ApolloFederation.Tests/CertificationSchema/AnnotationBased/__snapshots__/CertificationTests.Subgraph_SDL.snap b/src/HotChocolate/ApolloFederation/test/ApolloFederation.Tests/CertificationSchema/AnnotationBased/__snapshots__/CertificationTests.Subgraph_SDL.snap index c3e4cb2890b..5430dbe40ec 100644 --- a/src/HotChocolate/ApolloFederation/test/ApolloFederation.Tests/CertificationSchema/AnnotationBased/__snapshots__/CertificationTests.Subgraph_SDL.snap +++ b/src/HotChocolate/ApolloFederation/test/ApolloFederation.Tests/CertificationSchema/AnnotationBased/__snapshots__/CertificationTests.Subgraph_SDL.snap @@ -1,4 +1,4 @@ -schema @link(url: "https:\/\/specs.apollo.dev\/federation\/v2.0", import: [ "@extends", "@key", "@provides", "FieldSet", "@external" ]) { +schema @link(url: "https:\/\/specs.apollo.dev\/federation\/v2.0", import: [ "@key", "@provides", "FieldSet", "@external" ]) { query: Query } @@ -20,13 +20,13 @@ type ProductVariation { id: ID! } -type Query @extends { +type Query { product(id: ID!): Product _service: _Service! _entities(representations: [_Any!]!): [_Entity]! } -type User @key(fields: "email") @extends { +type User @key(fields: "email") { email: ID! @external totalProductsCreated: Int @external } @@ -39,9 +39,6 @@ type _Service { "Union of all types that key directive applied. This information is needed by the Apollo federation gateway." union _Entity = Product | User -"Directive to indicate that marks target object as extending part of the federated schema." -directive @extends on OBJECT | INTERFACE - "Directive to indicate that a field is owned by another service, for example via Apollo federation." directive @external on FIELD_DEFINITION diff --git a/src/HotChocolate/ApolloFederation/test/ApolloFederation.Tests/CertificationSchema/CodeFirst/__snapshots__/CertificationTests.Schema_Snapshot.snap b/src/HotChocolate/ApolloFederation/test/ApolloFederation.Tests/CertificationSchema/CodeFirst/__snapshots__/CertificationTests.Schema_Snapshot.snap index 3fde4975778..a46f907f22c 100644 --- a/src/HotChocolate/ApolloFederation/test/ApolloFederation.Tests/CertificationSchema/CodeFirst/__snapshots__/CertificationTests.Schema_Snapshot.snap +++ b/src/HotChocolate/ApolloFederation/test/ApolloFederation.Tests/CertificationSchema/CodeFirst/__snapshots__/CertificationTests.Schema_Snapshot.snap @@ -1,4 +1,4 @@ -schema @link(url: "https:\/\/specs.apollo.dev\/federation\/v2.0", import: [ "@extends", "@key", "@provides", "@external", "FieldSet" ]) { +schema @link(url: "https:\/\/specs.apollo.dev\/federation\/v2.0", import: [ "@key", "@provides", "@external", "FieldSet" ]) { query: Query } @@ -20,13 +20,13 @@ type ProductVariation { id: ID! } -type Query @extends { +type Query { product(id: ID!): Product _service: _Service! _entities(representations: [_Any!]!): [_Entity]! } -type User @extends @key(fields: "email") { +type User @key(fields: "email") { email: ID! @external totalProductsCreated: Int @external } @@ -39,9 +39,6 @@ type _Service { "Union of all types that key directive applied. This information is needed by the Apollo federation gateway." union _Entity = Product | User -"Directive to indicate that marks target object as extending part of the federated schema." -directive @extends on OBJECT | INTERFACE - "Directive to indicate that a field is owned by another service, for example via Apollo federation." directive @external on FIELD_DEFINITION diff --git a/src/HotChocolate/ApolloFederation/test/ApolloFederation.Tests/CertificationSchema/CodeFirst/__snapshots__/CertificationTests.Subgraph_SDL.snap b/src/HotChocolate/ApolloFederation/test/ApolloFederation.Tests/CertificationSchema/CodeFirst/__snapshots__/CertificationTests.Subgraph_SDL.snap index 3fde4975778..a46f907f22c 100644 --- a/src/HotChocolate/ApolloFederation/test/ApolloFederation.Tests/CertificationSchema/CodeFirst/__snapshots__/CertificationTests.Subgraph_SDL.snap +++ b/src/HotChocolate/ApolloFederation/test/ApolloFederation.Tests/CertificationSchema/CodeFirst/__snapshots__/CertificationTests.Subgraph_SDL.snap @@ -1,4 +1,4 @@ -schema @link(url: "https:\/\/specs.apollo.dev\/federation\/v2.0", import: [ "@extends", "@key", "@provides", "@external", "FieldSet" ]) { +schema @link(url: "https:\/\/specs.apollo.dev\/federation\/v2.0", import: [ "@key", "@provides", "@external", "FieldSet" ]) { query: Query } @@ -20,13 +20,13 @@ type ProductVariation { id: ID! } -type Query @extends { +type Query { product(id: ID!): Product _service: _Service! _entities(representations: [_Any!]!): [_Entity]! } -type User @extends @key(fields: "email") { +type User @key(fields: "email") { email: ID! @external totalProductsCreated: Int @external } @@ -39,9 +39,6 @@ type _Service { "Union of all types that key directive applied. This information is needed by the Apollo federation gateway." union _Entity = Product | User -"Directive to indicate that marks target object as extending part of the federated schema." -directive @extends on OBJECT | INTERFACE - "Directive to indicate that a field is owned by another service, for example via Apollo federation." directive @external on FIELD_DEFINITION