feat(guide): query keys — use the scaffold's generated constant, never an inline array (build42 Contact)#184
Open
agjs wants to merge 3 commits into
mainagjs/tsforge:mainfrom
fix/query-key-constant-idiomagjs/tsforge:fix/query-key-constant-idiomCopy head branch name to clipboard
Open
feat(guide): query keys — use the scaffold's generated constant, never an inline array (build42 Contact)#184agjs wants to merge 3 commits intomainagjs/tsforge:mainfrom fix/query-key-constant-idiomagjs/tsforge:fix/query-key-constant-idiomCopy head branch name to clipboard
agjs wants to merge 3 commits into
mainagjs/tsforge:mainfrom
fix/query-key-constant-idiomagjs/tsforge:fix/query-key-constant-idiomCopy head branch name to clipboard
Conversation
…array queryKey) — build42 Contact build42 Contact advanced past parent-FK/anatomy/no-jsx-computation to near-green, then rotated on nonConstantQueryKey (react-component-architecture): a useQuery/useMutation queryKey/mutationKey whose value is an array literal STARTING with a string (queryKey: ["contact", id]) is rejected. The guide never mentioned query keys. Root-caused from the rule source (fires only on an ArrayExpression whose first element is a string Literal) and front-loaded the exact idiom: define keys once in <Feature>.constants.ts as a const (CONTACT_QUERY_KEYS.all/list/detail), reference them in the query, and invalidate with the SAME constant in mutations' onSuccess (so the list refreshes). Noted the spread-of-constant escape (only a bare-string-first array trips). New refine-prompt test. Full core suite green.
…reuse in the test
Panel PASS with ag1 notes, addressed: (1) the parenthetical taught that an inline spread passes the
rule — but at the call site re-scatters the key even though it lints
clean. Reframed: the CALL SITE always references the constant factory (KEYS.list()/.detail(id)),
never an inline array; the spread lives INSIDE the constants file's detail(id) factory (single source
of truth). (2) The invalidation test only checked the pre-existing 'invalidateQueries' text; now it
asserts the exact constant reuse (invalidateQueries({ queryKey: CONTACT_QUERY_KEYS.all })) + the
no-inline-array / single-source guidance. Full core suite green.
…perty access) — not invented factories
Panel wrong-idiom (correct): my QUERY_KEYS shape (hierarchical all/list()/detail() factories, KEYS.list()
call, invalidate KEYS.all) CONFLICTED with what the scaffold's new:feature ALREADY generates gate-green:
export const CONTACT_QUERY_KEYS = { list: ['contact','list'] as const }; // static tuple, accessed .list
It would have forced needless rewrites of working files + a partial-apply footgun (list becomes a function
but bare .list usages hand React Query a function as the key → broken refresh). Real scaffold features use
static tuples for fixed keys, factories ONLY for parameterized ones. build42's actual error was INLINING an
array, not the key shape. Rewrote the guidance to: USE the generated CONTACT_QUERY_KEYS.list (property, as
wired), invalidate with the SAME .list, and ADD keys in the scaffold's style — static tuple for fixed, a
factory only for a parameterized detail(id); never rewrite the static list into a function. Test now pins
the scaffold shape + property access + parameterized-only factory, and locks out BOTH earlier mis-teachings
(the inline-spread loophole and the .list() rewrite). Full core suite green.
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.
Wall (build42 Contact)
Contact advanced past parent-FK/anatomy/no-jsx-computation to near-green, then rotated on
nonConstantQueryKey(react-component-architecture): auseQuery/useMutationqueryKey/mutationKeythat is an inline array literal starting with a string (queryKey: ["contact", id]) is rejected — the model inlined the array instead of using the constant.Fix (aligned to the scaffold — not an invented shape)
The scaffold's
new:featurealready generatesCONTACT_QUERY_KEYS = { list: ["contact","list"] as const }(a static tuple, accessed as.list). The guide now teaches: reference that generated constant (queryKey: CONTACT_QUERY_KEYS.list) and invalidate the list in mutations'onSuccesswith the same.list; add an extra key in the scaffold's style — a static tuple for a fixed key, a factory only for a parameterized one (detail: (id) => ["contact", id] as const); and never rewrite the staticlisttuple into a function (bare.listusages would hand React Query a function as the key → silently broken refresh).An earlier iteration of this PR invented a hierarchical
all/list()/detail()factory shape; the panel correctly flagged that it conflicts with the gate-green scaffold and creates a partial-apply footgun — corrected to match the scaffold exactly (root-caused from the generatedContact.constants.ts+ the rule source).Tests
boringstack-refine-prompt.test.tspins the scaffold shape, property access (.list), same-constant invalidation, parameterized-only factory, and locks out both earlier mis-teachings (the inline-spread loophole and the.list()rewrite). Full core suite green. Panel PASS.🤖 Generated with Claude Code