Skip to content

Fix fields added by type interceptors missing the default resolver cost - #10885

Merged
glen-84 merged 1 commit into
mainfrom
gai/cost-defaults-after-type-interceptors
Nov 12, 2026
Merged

glen-84 merged 1 commit into
mainfrom
gai/cost-defaults-after-type-interceptors

Conversation

@glen-84

@glen-84 glen-84 commented Nov 12, 2026

Copy link
Copy Markdown
Member

Summary

  • CostTypeInterceptor now runs after every other type interceptor. Its position, int.MaxValue, equalled the default position of a type interceptor (uint.MaxValue / 2), so it ran in registration order among them, and AddGraphQLServer() registers it first. A field that a later interceptor added in OnBeforeCompleteType therefore missed the default resolver cost of 10 that the cost analysis docs give every field without a pure resolver.
  • In the default setup this affects _entities from AddApolloFederation(), the query field from AddQueryFieldToMutationPayloads(), and fields with a resolver that an application's own interceptor adds. Each selection of them now has a field cost of 10, up from 1 for a field that returns an object, interface, or union type and 0 otherwise, so an operation close to MaxFieldCost can now be rejected. The new 16.7 to 16.8 migration guide lists this under behavioral breaking changes.

Test plan

  • New InterceptorTests case: a field that an interceptor registered after AddGraphQLServer() adds gets @cost(weight: "10"). It fails without the position change.
  • CostAnalysis.Tests, ApolloFederation.Tests, Types.Mutations.Tests, Caching.Tests, and Fusion.Connectors.ApolloFederation.Compliance.Tests pass on net10.0, with no snapshot changes.
  • Prettier, markdownlint, and cspell pass on the migration guide.

Copilot AI lite review requested due to automatic review settings November 12, 2026 07:55
@github-actions github-actions Bot added 📚 documentation This issue is about working on our documentation. 🌶️ hot chocolate labels Nov 12, 2026

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.

🟢 Approval recommended

No active review issues are identified, and the change includes targeted regression coverage for interceptor ordering and the documented cost behavior.

No open issues 🎉

What changed in this PR

Fixes cost-analysis interceptor ordering so fields added by later type interceptors receive the configured default resolver cost, and documents the behavioral impact when migrating from Hot Chocolate 16.7 to 16.8.

Changes:

  • Moves CostTypeInterceptor to the final interceptor position.
  • Adds regression coverage for fields added by later interceptors.
  • Adds and registers a 16.7-to-16.8 migration guide describing the updated cost behavior.
File Description
website/​content/​docs/​hotchocolate/​migrating/​structure.yaml Registers the new 16.7-to-16.8 migration guide in the documentation navigation.
website/​content/​docs/​hotchocolate/​migrating/​migrate-from-16-7-to-16-8.md Documents the default resolver cost applied to fields added by type interceptors and the migration impact.
src/​HotChocolate/​CostAnalysis/​test/​CostAnalysis.Tests/​InterceptorTests.cs Adds regression coverage verifying that fields added by later interceptors receive a resolver cost of 10.
src/​HotChocolate/​CostAnalysis/​src/​CostAnalysis/​CostTypeInterceptor.cs Ensures cost metadata is applied after other type interceptors complete their modifications.

Review effort: Lite

@github-actions

Copy link
Copy Markdown
Contributor

Patch coverage

100.0% of changed lines covered (1/1)

File Covered Changed Patch %
…/CostAnalysis/src/CostAnalysis/CostTypeInterceptor.cs 1 1 100.0% 🟢

Project coverage: 59.5% (322349/541546 lines)

@glen-84
glen-84 merged commit a089b0a into main Nov 12, 2026
308 of 310 checks passed
@glen-84
glen-84 deleted the gai/cost-defaults-after-type-interceptors branch November 12, 2026 08:09
This was referenced Nov 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

📚 documentation This issue is about working on our documentation. 🌶️ hot chocolate

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants