Skip to content

docs(search-api-graphql): state exactly what a fragment costs - #918

Merged
ddeboer merged 2 commits into
mainfrom
docs/fragment-cost-accuracy
Oct 16, 2026
Merged

ddeboer merged 2 commits into
mainfrom
docs/fragment-cost-accuracy

Conversation

@ddeboer

@ddeboer ddeboer commented Oct 16, 2026 •

Copy link
Copy Markdown
Member

Follow-up to #916. Its docs said a flattened fragment spread no longer multiplies the cost of what it contains. That holds for a nested fragment, but not for a spread at the operation root: { ...Q } fragment Q on Query { … } still costs its contents 1.5×. A query costing 14.75 inlined costs 25.125 written that way.

  • Correct the reference docs and give exact figures from graphql-armor’s cost rule: a nested inline fragment adds 2, a named spread adds 3, a root-level spread costs its contents 1.5×, and a repeat of a named fragment costs 1 plus 1.5× what its first spread scored, even in another operation of the same document.
  • Describe the same rules in the JSDoc for maxDepth and maxCost, so they show up in editor hover text.
  • Add a test for each case, reading the score from armor’s rejection message, so a graphql-armor upgrade that changes the scoring fails here.
  • State that the cost limit bounds a query’s shape, not its result volume: perPage doesn’t enter the cost (armor scales list cost only for first/last), so a page of 100 scores like a page of 1. maxPerPage (default 100) is what bounds result volume. A per-field cost estimator would need graphql-query-complexity in place of armor’s cost plugin; not worth it while maxPerPage holds.

- Correct the claim that a flattened spread never multiplies cost: one at the operation root does
- Give the fixed cost of inline fragments and named spreads, and the exact cost of a repeat
- Describe flattening in the maxDepth and maxCost JSDoc
- Pin each case in tests, so a graphql-armor upgrade that changes scoring fails
@ddeboer
ddeboer merged commit 3336fb9 into main Oct 16, 2026
4 checks passed
@ddeboer
ddeboer deleted the docs/fragment-cost-accuracy branch October 16, 2026 12:34
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.

1 participant