-
Notifications
You must be signed in to change notification settings - Fork 348
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[generator] Apollo Federation v2 support (#1459)
Federation v2 is an evolution of the Federation spec to make it more powerful, flexible and easier to adapt. While v1 and v2 schemas are similar in many ways, Federation v2 relaxes some of the constraints and adds additional capabilities. See [Apollo documentation](https://www.apollographql.com/docs/federation/federation-2/new-in-federation-2/) for details. By default, `graphql-kotlin-federation` library will generate Federation v1 compatible schema. In order to generate v2 compatible schema you have to explicitly opt-in by specifying `optInFederationV2 = true` on your instance of `FederatedSchemaGeneratorHooks`. ```kotlin val myHooks = FederatedSchemaGeneratorHooks(resolvers = myFederatedResolvers, optInFederationV2 = true) val myConfig = FederatedSchemaGeneratorConfig( supportedPackages = "com.example", hooks = myHooks ) toFederatedSchema( config = myConfig, queries = listOf(TopLevelObject(MyQuery())) ) ``` New directives * `@contact` - provides contact information to the given subgraph * `@inaccessible` - allows to exclude schema elements from the GraphQL Gateway * `@link` - imports external entities to the schema * `@override` - migrate field resolution logic from one subgraph to another * `@shareable` - marks fields and objects as resolvable across multiple subgraphs * `@tag` - adds additional metadata to schema elements (used by Apollo Contracts)
- Loading branch information
1 parent
5721ea3
commit 5f09656
Showing
26 changed files
with
1,210 additions
and
52 deletions.
There are no files selected for viewing
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
64 changes: 64 additions & 0 deletions
64
.../main/kotlin/com/expediagroup/graphql/generator/federation/directives/ContactDirective.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,64 @@ | ||
/* | ||
* Copyright 2022 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.DirectiveLocation | ||
|
||
/** | ||
* ```graphql | ||
* directive @contact( | ||
* "Contact title of the subgraph owner" | ||
* name: String! | ||
* "URL where the subgraph's owner can be reached" | ||
* url: String | ||
* "Other relevant notes can be included here; supports markdown links" | ||
* description: String | ||
* ) on SCHEMA | ||
* ``` | ||
* | ||
* Contact schema directive can be used to provide team contact information to your subgraph schema. This information is automatically parsed and displayed by Apollo Studio. | ||
* | ||
* Example usage on schema class: | ||
* ```kotlin | ||
* @ContactDirective( | ||
* name = "My Team Name", | ||
* url = "https://myteam.slack.com/archives/teams-chat-room-url", | ||
* description = "send urgent issues to [#oncall](https://yourteam.slack.com/archives/oncall)." | ||
* ) | ||
* class MySchema | ||
* ``` | ||
* | ||
* @param name subgraph owner name | ||
* @param url optional URL where the subgraph's owner can be reached | ||
* @param description optional additional information about contacting the owners, can include markdown links | ||
* | ||
* @see <a href="https://www.apollographql.com/docs/studio/federated-graphs/#subgraph-contact-info">Subgraph Contact Info</a> | ||
*/ | ||
@GraphQLDirective( | ||
name = "contact", | ||
description = "Provides contact information of the owner responsible for this subgraph schema.", | ||
locations = [DirectiveLocation.SCHEMA] | ||
) | ||
annotation class ContactDirective( | ||
/** Contact title of the subgraph owner */ | ||
val name: String, | ||
/** URL where the subgraph's owner can be reached */ | ||
val url: String = "", | ||
/** Other relevant notes can be included here; supports markdown links */ | ||
val description: String = "" | ||
) |
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
Oops, something went wrong.