## Context
Grant-gated query factories returned `queryFn: skipToken` when the
caller had no grant. TanStack Query keeps one options object per cache
entry, overwritten by whichever observer rendered last. When that was a
grant-less observer, invalidation refetched with `skipToken` and failed
with `Missing queryFn`, breaking the query for every other observer on
the key. #53075 patched two call sites; this fixes the factories.
## Changes
- New `grantedQueryOptions` helper (`data/granted-query-options.ts`).
Without a grant, the factory sets `queryFn: undefined` instead of
`skipToken`, so TanStack borrows the query function from a subscribed
observer that has one. The caller's `enabled` applies only when the
factory has a query function.
- `apiKeysQueryOptions`, `revealedApiKeysQueryOptions`,
`branchesQueryOptions`, `branchQueryOptions` and
`branchDiffQueryOptions` take caller options as a second argument. Call
sites change from `useQuery({ ...f(vars), enabled })` to
`useQuery(f(vars, { enabled }))`, so callers can't override the grant
gate.
- New type-aware `fga/no-spread-granted-query-options` lint rule
(error). `grantedQueryOptions` returns a type-only brand, and the rule
flags any spread or `Object.assign` of a branded value, however it was
built or named.
- Restores typed linting as a separate pass
(`eslint.type-checks.config.cjs`, run by `pnpm lint` via
`lint:type-checks`), as #44678 did. Enabling type info in the main
config changes what other plugins report, so it stays separate.
- `studio-queries` skill documents the pattern.
Callers still pass their own grant, so the UI gates on the same grant
the request carries.
## Testing
- `data/api-keys/api-keys-query.test.tsx`: a granted and a grant-less
component share the key, with the grant-less one rendering last;
invalidation via the delete mutation refetches successfully. Fails on
master with `Missing queryFn`.
- `data/granted-query-options.test.ts`: `enabled` gating, factory fields
win over caller fields, `select` type inference.
- Lint rule cases in `scripts/__tests__/fga-eslint-rules.test.ts`.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
## Problem
Resolves FE-4691.
Builds on #52238, which added `unguarded.migrating` at every call site
that hits an FGA-annotated endpoint. Nothing stops new call sites from
adding to that backlog, nothing checks that `unguarded.byDesign` carries
a real reason, and type suppressions or the untyped
`fetchGet`/`fetchPost` helpers can skip the grant check entirely.
## Solution
Adds a local `fga` ESLint plugin
(`apps/studio/scripts/eslint-rules/fga.cjs`):
- **`fga/no-unguarded-migrating`** (warn, ratcheted): flags each
`unguarded.migrating`. Added to `scripts/ratchet-rules.json` with its
baseline in `.github/eslint-rule-baselines.json`, so the count can only
go down.
- **`fga/unguarded-by-design-reason`** (error):
`unguarded.byDesign(...)` must take a single non-empty string literal.
- **`fga/no-fetch-type-bypass`** (error):
- flags `@ts-ignore` / `@ts-expect-error` / `@ts-nocheck` that would
suppress a grant error on a `get`/`post`/`put`/`patch`/`del` call from
`data/fetchers`: directives targeting the call's first line, an
argument's first line, or the `grant` property;
- flags imports of the untyped `fetchGet` / `fetchPost`.
Directives on `params` lines inside the init (used today to work around
spec mismatches) aren't flagged, since they can't hide a missing grant.
Existing bypasses are listed in `FETCH_TYPE_BYPASS_EXCEPTIONS` in
`eslint.config.cjs`: the 3 `@ts-ignore` fetch calls and the 15 files
using `fetchGet`/`fetchPost`. Test files are exempt, since they assert
type errors on purpose.
## Testing
- RuleTester suite in `scripts/__tests__/fga-eslint-rules.test.ts`
- `pnpm --filter studio run lint:ratchet` passes; `eslint --quiet` is
clean