Add key inferrence for lookups#9819
Merged
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR adds automatic @key directive inference for source schemas by deriving entity key selection sets from @lookup field arguments (including @is field selection maps), so published source schemas better describe resolvable entity keys.
Changes:
- Introduces
SourceSchemaKeyInferenceTypeInterceptorto infer and apply@key(fields: ...)directives to lookup return types (and relevant possible types). - Updates the
@keydirective definition to berepeatable, enabling multiple inferred/manual keys on the same type. - Adds a new schema option (
InferKeysFromLookups) and enables it by default viaAddSourceSchemaDefaults, while registering the interceptor in the default executor builder.
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| src/HotChocolate/Core/src/Types/Types/Composite/SourceSchemaKeyInferenceTypeInterceptor.cs | New interceptor that collects @lookup fields and applies inferred, deduplicated @key directives to target types. |
| src/HotChocolate/Core/src/Types/Types/Composite/Directives/EntityKey.cs | Makes @key repeatable to support multiple keys (manual + inferred) on OBJECT/INTERFACE. |
| src/HotChocolate/Core/src/Types/SchemaOptions.cs | Adds InferKeysFromLookups option and copies it in FromOptions. |
| src/HotChocolate/Core/src/Types/IReadOnlySchemaOptions.cs | Adds InferKeysFromLookups option to the read-only schema options API surface. |
| src/HotChocolate/Core/src/Types/Execution/DependencyInjection/RequestExecutorServiceCollectionExtensions.cs | Registers the new interceptor (gated by the new option). |
| src/HotChocolate/Core/src/Types/Execution/DependencyInjection/RequestExecutorBuilderExtensions.Composite.cs | Enables key inference by default for source schema defaults. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
This was referenced Jun 3, 2026
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
No description provided.