Skip to content

Add key inferrence for lookups#9819

Merged
michaelstaib merged 6 commits into
mainfrom
mst/infer-keys
Jun 3, 2026
Merged

Add key inferrence for lookups#9819
michaelstaib merged 6 commits into
mainfrom
mst/infer-keys

Conversation

@michaelstaib

Copy link
Copy Markdown
Member

No description provided.

Copilot AI review requested due to automatic review settings June 2, 2026 12:17

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 SourceSchemaKeyInferenceTypeInterceptor to infer and apply @key(fields: ...) directives to lookup return types (and relevant possible types).
  • Updates the @key directive definition to be repeatable, enabling multiple inferred/manual keys on the same type.
  • Adds a new schema option (InferKeysFromLookups) and enables it by default via AddSourceSchemaDefaults, 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.

@michaelstaib michaelstaib merged commit b92cbd6 into main Jun 3, 2026
5 of 6 checks passed
@michaelstaib michaelstaib deleted the mst/infer-keys branch June 3, 2026 06:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants