Skip to content

fix: stop flagging default-resolved fields as GraphQL N+1 - #63

Merged
JacobCoffee merged 1 commit into
mainfrom
fix/graphql-n-plus-one-false-positive
Oct 11, 2026
Merged

JacobCoffee merged 1 commit into
mainfrom
fix/graphql-n-plus-one-false-positive

Conversation

@JacobCoffee

Copy link
Copy Markdown
Owner

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 for id/title (no custom resolver, no I/O) produced a false "N+1" warning, even though nothing was done per item.

What changed

  • TrackedResolver gained an is_default_resolver flag, set in the Strawberry extension's resolve() hook using Strawberry's own strawberry.resolvers.is_default_resolver(next_resolver) check (falls back to False when Strawberry isn't installed).
  • N1Analyzer.analyze() now skips resolvers where is_default_resolver is True, so plain field reads are never flagged.
  • Custom per-item resolvers (e.g. Post.author, User.posts) are still flagged once they hit the threshold, since they are not Strawberry's default resolver.

How verified

  • Added regression tests: test_ignores_default_resolvers (5 default-resolved fields → no pattern) and test_flags_custom_resolver_called_per_item (3 custom resolver calls → still flagged). make ci passes (660 tests).
  • Verified against examples/graphql_panel_example.py on 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 } } } (custom Post.author resolver run once per post) → panel shows Post.author Called 5x, still correctly flagged.

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).
Copilot AI balanced review requested due to automatic review settings October 11, 2026 00:32

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.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@github-actions

Copy link
Copy Markdown
Contributor
PR Preview Action v1.8.1

QR code for preview link

🚀 View preview at
https://JacobCoffee.github.io/debug-toolbar/pr-preview/pr-63/

Built to branch gh-pages at 2026-10-11 00:33 UTC.
Preview will be ready when the GitHub Pages deployment is complete.

@JacobCoffee
JacobCoffee enabled auto-merge (squash) October 11, 2026 00:34
@JacobCoffee
JacobCoffee merged commit c32b702 into main Oct 11, 2026
24 checks passed
@JacobCoffee
JacobCoffee deleted the fix/graphql-n-plus-one-false-positive branch October 11, 2026 00:36
This was referenced Oct 11, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants