Repository navigation
fix: stop flagging default-resolved fields as GraphQL N+1 - #63
Merged
Merged
Conversation
The N+1 detector counted every resolver call for a field, including plain attribute reads served by Strawberry's default resolver (e.g. a list of 3+ items where each item's id/title is a bare field). Those never do per-item I/O, so they aren't real N+1 patterns. Track whether a resolver is Strawberry's default resolver (strawberry.resolvers.is_default_resolver) and exclude default resolvers from N+1 detection, while still flagging custom resolvers (e.g. a field resolved once per list item via a user-defined resolver function).
Contributor
|
JacobCoffee
enabled auto-merge (squash)
October 11, 2026 00:34
This was referenced Oct 11, 2026
Merged
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.
What was wrong
The GraphQL N+1 detector (
N1Analyzer) flagged any field called 3+ times, including plain attribute reads served by Strawberry's default resolver. For example, querying a list of 3+ posts forid/title(no custom resolver, no I/O) produced a false "N+1" warning, even though nothing was done per item.What changed
TrackedResolvergained anis_default_resolverflag, set in the Strawberry extension'sresolve()hook using Strawberry's ownstrawberry.resolvers.is_default_resolver(next_resolver)check (falls back toFalsewhen Strawberry isn't installed).N1Analyzer.analyze()now skips resolvers whereis_default_resolverisTrue, so plain field reads are never flagged.Post.author,User.posts) are still flagged once they hit the threshold, since they are not Strawberry's default resolver.How verified
test_ignores_default_resolvers(5 default-resolved fields → no pattern) andtest_flags_custom_resolver_called_per_item(3 custom resolver calls → still flagged).make cipasses (660 tests).examples/graphql_panel_example.pyon port 8983 in a real browser:query { posts { id title } }(default resolvers only) → GraphQL panel shows 0 N+1 issues.query { posts { id title author { id name } } }(customPost.authorresolver run once per post) → panel showsPost.author Called 5x, still correctly flagged.