-
Notifications
You must be signed in to change notification settings - Fork 353
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
federation: add support for Apollo Federation subgraph spec v2.3 (#1661)
* federation: add support for Apollo Federation subgraph spec v2.3 Updates `federation` module to support Apollo Federation subgraph spec v2.3 Changes: * v2.2 - update `@shareable` definition to be repeatable to allow annotating both types and their extensions (NOTE: this functionality is not applicable to `graphql-kotlin`) * v2.3 - adds new `@interfaceObject` directive that allows you to extend interface entity functionality in subgraphs, i.e. by applying `@interfaceObject` directive on a type we provide meta information to the composition logic that this entity type is actually an interface in the supergraph. This allows us to extend interface functionality without knowing any of its implementing types. * fix integration tests * update remaining fed2.1 references with fed2.3 * update composition test to use latest router * update test schema to fed 2.3 * fix directive definitions * fix tests * fix definitions * add missing intf object IT
- Loading branch information
1 parent
be7d676
commit 10e9d84
Showing
26 changed files
with
449 additions
and
101 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
84 changes: 84 additions & 0 deletions
84
...tlin/com/expediagroup/graphql/generator/federation/directives/InterfaceObjectDirective.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
/* | ||
* Copyright 2023 Expedia, Inc | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.expediagroup.graphql.generator.federation.directives | ||
|
||
import com.expediagroup.graphql.generator.annotations.GraphQLDirective | ||
import graphql.introspection.Introspection | ||
|
||
/** | ||
* ```graphql | ||
* directive @interfaceObject on OBJECT | ||
* ``` | ||
* | ||
* This directive provides meta information to the router that this entity type defined within this subgraph is an interface in the supergraph. This allows you to extend functionality | ||
* of an interface across the supergraph without having to implement (or even be aware of) all its implementing types. | ||
* | ||
* Example: | ||
* Given an interface that is defined in another subgraph | ||
* | ||
* ```graphql | ||
* interface Product @key(fields: "id") { | ||
* id: ID! | ||
* description: String | ||
* } | ||
* | ||
* type Book implements Product @key(fields: "id") { | ||
* id: ID! | ||
* description: String | ||
* pages: Int! | ||
* } | ||
* | ||
* type Movie implements Product @key(fields: "id") { | ||
* id: ID! | ||
* description: String | ||
* duration: Int! | ||
* } | ||
* ``` | ||
* | ||
* We can extend Product entity in our subgraph and a new field directly to it. This will result in making this new field available to ALL implementing types. | ||
* | ||
* ```kotlin | ||
* @InterfaceObjectDirective | ||
* data class Product(val id: ID) { | ||
* fun reviews(): List<Review> = TODO() | ||
* } | ||
* ``` | ||
* | ||
* Which generates the following subgraph schema | ||
* | ||
* ```graphql | ||
* type Product @key(fields: "id") @interfaceObject { | ||
* id: ID! | ||
* reviews: [Review!]! | ||
* } | ||
* ``` | ||
*/ | ||
@GraphQLDirective( | ||
name = INTERFACE_OBJECT_DIRECTIVE_NAME, | ||
description = INTERFACE_OBJECT_DIRECTIVE_DESCRIPTION, | ||
locations = [Introspection.DirectiveLocation.OBJECT] | ||
) | ||
annotation class InterfaceObjectDirective | ||
|
||
internal const val INTERFACE_OBJECT_DIRECTIVE_NAME = "interfaceObject" | ||
private const val INTERFACE_OBJECT_DIRECTIVE_DESCRIPTION = "Provides meta information to the router that this entity type is an interface in the supergraph." | ||
|
||
internal val INTERFACE_OBJECT_DIRECTIVE_TYPE: graphql.schema.GraphQLDirective = graphql.schema.GraphQLDirective.newDirective() | ||
.name(INTERFACE_OBJECT_DIRECTIVE_NAME) | ||
.description(INTERFACE_OBJECT_DIRECTIVE_DESCRIPTION) | ||
.validLocations(Introspection.DirectiveLocation.OBJECT) | ||
.build() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...test/kotlin/com/expediagroup/graphql/generator/federation/FederatedSchemaGeneratorTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 16 additions & 0 deletions
16
...pediagroup/graphql/generator/federation/data/integration/composeDirective/CustomSchema.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.