Repository navigation
Fix UseConnection ignoring global paging options in cost analysis - #9975
Conversation
There was a problem hiding this comment.
Pull request overview
This PR addresses a cost analysis discrepancy where connection fields configured via [UseConnection] could ignore globally configured paging options (notably MaxPageSize) during schema-cost metadata generation, leading to skewed @listSize(assumedSize: ...) values.
Changes:
- Update
[UseConnection]attribute configuration to set merged paging options (including global defaults) onto field features during type creation. - Add regression tests validating that
@listSize.assumedSizehonors globalMaxPageSizefor[UseConnection]when no per-field override is provided. - Add coverage for explicit per-field overrides via
[UseConnection(MaxPageSize = ...)].
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| src/HotChocolate/CostAnalysis/test/CostAnalysis.Tests/ConnectionOverridePagingCostTests.cs | Adds regression tests ensuring @listSize.assumedSize reflects global and per-field paging options for [UseConnection]. |
| src/HotChocolate/Core/src/Types.CursorPagination/Extensions/UseConnectionAttribute.cs | Ensures paging options stored on field features are merged with global paging options early enough for cost analysis defaults. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| // [UsePaging] and [UseConnection] are two ways to declare the same connection field, so they | ||
| // must derive the same @listSize.assumedSize from the global MaxPageSize when no per-field | ||
| // override is set. The source-gen connection shape (connection flag + [UseConnection]) must | ||
| // match too. | ||
| [Fact] | ||
| public async Task ListSize_AssumedSize_Should_Be_Equal_For_UsePaging_And_UseConnection_Without_Override() | ||
| { | ||
| // arrange & act | ||
| var usePaging = await GetBooksAssumedSizeAsync(b => b.AddQueryType<UsePagingQuery>()); | ||
| var useConnection = await GetBooksAssumedSizeAsync(b => b.AddQueryType<NoOverrideQueryType>()); | ||
| var sourceGenConnection = await GetBooksAssumedSizeAsync(b => b.AddQueryType<NoOverrideQueryType>()); | ||
|
|
||
| // assert | ||
| Assert.Equal(100, usePaging); | ||
| Assert.Equal(100, useConnection); | ||
| Assert.Equal(100, sourceGenConnection); | ||
| Assert.Equal(usePaging, useConnection); | ||
| Assert.Equal(usePaging, sourceGenConnection); | ||
| } |
Code Coverage OverviewLanguages: C# C# / code-coverage/dotnetThe overall coverage in the Show a code coverage summary of the most impacted files.
Code Coverage is in Public Preview. Learn more and provide us with your feedback. |
Patch coverage100.0% of changed lines covered (1/1)
Project coverage: 52.4% (215284/411029 lines) |
No description provided.