-
Notifications
You must be signed in to change notification settings - Fork 348
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
BREAKING(feat(federation)): full @link
support
#1816
Merged
Merged
Conversation
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
dariuszkuc
added
type: enhancement
New feature or request
changes: major
Changes require a major version
module: generator
Issue affects the schema generator and federation code
labels
Jul 27, 2023
dariuszkuc
commented
Jul 27, 2023
dariuszkuc
commented
Jul 27, 2023
...rator/src/main/kotlin/com/expediagroup/graphql/generator/internal/types/generateDirective.kt
Outdated
Show resolved
Hide resolved
dariuszkuc
commented
Jul 27, 2023
...otlin-schema-generator/src/main/kotlin/com/expediagroup/graphql/generator/SchemaGenerator.kt
Outdated
Show resolved
Hide resolved
dariuszkuc
commented
Jul 27, 2023
...a-generator/src/main/kotlin/com/expediagroup/graphql/generator/hooks/SchemaGeneratorHooks.kt
Outdated
Show resolved
Hide resolved
dariuszkuc
commented
Jul 27, 2023
...rator/src/main/kotlin/com/expediagroup/graphql/generator/internal/types/generateDirective.kt
Outdated
Show resolved
Hide resolved
Introduce full `@link` support that includes namespacing and renaming of the imported elements. The `@link` directive allows users to link definitions within the document to external schemas. It is the core feature of the Apollo federation v2. While imported elements still need to have their definitions in the local schema, `@link` allows users to namespace and/or rename those items to avoid any local type conflicts. By default, all external types that are not explicitly imported have to be namespaced using the spec name or a provided custom namespace. Updated `@link` definition ```graphql directive @link(url: String!, as: String, import: [link__Import]) repeatable on SCHEMA scalar link__Import ``` * url - external specification url * as - optional custom namespace * import - list of elements to import, can either be simple Strings (e.g. `@key`) or custom imports that rename elements (e.g. `{ name: "@key", as: "@mykey" }`) By default, `graphql-kotlin` will continue to apply `@link` directive using latest supported federation specification but will only auto-import federation specific directives up to version 2.3 and only if they are present (i.e. applied to an element) in the schema. All new fed v2.4+ won't be included in the auto-imports and instead will be namespaced with the spec name, e.g. `@federation__authenticated`. Users can provide custom `@link` information by providing a schema object with `@LinkDirective` information, e.g. ```kotlin @LinkDirective(url = "https://specs.apollo.dev/federation/v2.3", `as`: "fed", import = [LinkImport(name = "@key", `as` = "@mykey"), LinkImport(name = "@requires")]) class MyCustomLinkSchema ``` Will generate following schema ```graphql schema @link(as: "fed", import : [{name : "@key", as : "@mykey"}, "@requires"], url : "https://specs.apollo.dev/federation/v2.3"){ query: Query } // directive imported with custom name "Space separated list of primary keys needed to access federated object" directive @mykey(fields: fed__FieldSet!, resolvable: Boolean = true) repeatable on OBJECT | INTERFACE // directive imported with same name "Specifies required input field set from the base type for a resolver" directive @requires(fields: fed__FieldSet!) on FIELD_DEFINITION // type imported with custom namespace "Federation type representing set of fields" scalar fed__FieldSet ``` When importing custom specifications, in order to be able to identify whether element is part of custom specification, we need to annotate it with new `@LinkedSpec` annotation. All federation directives were updated to rely on this mechanism, e.g. ```kotlin @LinkedSpec(FEDERATION_SPEC) @repeatable @GraphQLDirective( name = KEY_DIRECTIVE_NAME, description = KEY_DIRECTIVE_DESCRIPTION, locations = [DirectiveLocation.OBJECT, DirectiveLocation.INTERFACE] ) annotation class KeyDirective(val fields: FieldSet, val resolvable: Boolean = true) ```
samuelAndalon
approved these changes
Sep 8, 2023
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
changes: major
Changes require a major version
module: generator
Issue affects the schema generator and federation code
type: enhancement
New feature or request
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
📝 Description
Introduce full
@link
support that includes namespacing and renaming of the imported elements.The
@link
directive allows users to link definitions within the document to external schemas. It is the core feature of the Apollo federation v2. While imported elements still need to have their definitions in the local schema,@link
allows users to namespace and/or rename those items to avoid any local type conflicts. By default, all external types that are not explicitly imported have to be namespaced using the spec name or a provided custom namespace.Updated
@link
definition@key
) or custom imports that rename elements (e.g.{ name: "@key", as: "@myKey" }
)By default,
graphql-kotlin
will continue to apply@link
directive using latest supported federation specification but will only auto-import federation specific directives up to version 2.3 and only if they are present (i.e. applied to an element) in the schema. All new fed v2.4+ won't be included in the auto-imports and instead will be namespaced with the spec name, e.g.@federation__authenticated
.Users can provide custom
@link
information by providing a schema object with@LinkDirective
information, e.g.Will generate following schema
When importing custom specifications, in order to be able to identify whether element is part of custom specification, we need to annotate it with new
@LinkedSpec
annotation. All federation directives were updated to rely on this mechanism, e.g.🔗 Related Issues