Repository navigation
feat(javascript): recognize tRPC procedures and GraphQL operations - #1670
Conversation
Record RPC client syntax as network endpoint candidates in both analyze_javascript_application and analyze_web_bundle, distinguished by mechanism: - trpc:procedure:<method> keeps the static member path of root.<path>.<method>(...), which tRPC proxies preserve through identifier minification. React hooks and TanStack option factories are recognized directly. Vanilla query/mutate need a root bound to createTRPCClient/createTRPCProxyClient, or a tRPC source marker with a router path of at least two segments; subscribe needs the marker and a tRPC observer argument. `this` roots, browser globals and RTK Query `endpoints` chains are never procedures; cache-key helpers are excluded. - trpc:link:<link> records the literal url of documented HTTP links. - graphql:<type> records named operations from string and cooked template literals with a valid operation header, and from precompiled OperationDefinition objects; a graphql-tag loc.source.body copy is not reported twice. Method, callback and factory names follow @trpc/client and React/TanStack integration sources and documentation for 11.19. Carrier segments before the router path, useUtils helpers and minifier-renamed links remain documented limitations. Validation: typecheck; domain tests for recognition and false positives (Apollo, RxJS, stores, RTK Query, browser globals, prose); web bundle analyzer test; end-to-end analysis of a minified fixture through the built MCP server on Windows 11. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits. |
|
TL;DR: I tested this on Linux, after the merge. tRPC hooks and named GraphQL operations are now found, plain or minified. A client built in another file is missed, and so are routers named like browser globals. This PR merged as 3a7a307 (#1670). I tested main at 17f7040 (#1682) against 83e5255, the commit just before the merge. Results
I wrote small client files and compared the endpoint list with what each file really calls. Each file ran plain and then minified three ways. The ways were terser, esbuild, and an esbuild bundle with the real libraries. Before the merge, every file gave 0 candidates. Counts below are for main, on Node 24.18.0.
A procedure whose first name is Why the other misses happenThe minifier renames
False positives
The PR matches hooks and option factories by name alone, so the made-up roots follow its rule. The wrong report follows the PR's own rule: the text Real app: create-t3-app (MIT), commit 4709861f7. I took its example Not run
Thanks, pompiliodonatoapp, for the feature and for the tests. Test setup
Commands🤖 Generated with Claude Code (Sonnet 5.5, verified by Opus 5.5) 🦊 |
|
Thank you, @pompiliodonatoapp, for teaching the analyzers to recognize tRPC procedures and named GraphQL operations. Those are useful leads that literal |
Summary
Static analysis records RPC client syntax as network endpoint candidates in
both
analyze_javascript_applicationandanalyze_web_bundle. Before thischange, tRPC and GraphQL clients contributed no endpoints, because the calls
are not string-literal
fetch/XHR/WebSocket arguments. No existing issue islinked; this is proposed as an enhancement.
Problem and expected behavior
In a minified tRPC client,
e.invoice.list.useQuery({...})andn.empresa.byCnpj.query(...)name server procedures that a feature traceneeds, and so do GraphQL documents such as
query ListarNotas($competencia: String!) { ... }. Expected: these appear asendpoint candidates with an explicit
mechanism, without turning Apollo, RxJS,store or browser APIs into false procedures.
Change and scope
src/domain/javascript/javascriptRpcEndpoints.tsis a per-source pre-orderscan, used by both analyzers.
trpc:procedure:<method>records the static member path ofroot.<path>.<method>(...).query/mutateneed a root bound tocreateTRPCClient/createTRPCProxyClient, or a tRPC source marker(
TRPCClientError,trpc-accept,/trpc) together with a path of atleast two segments.
subscribeneeds the marker plus a tRPC observer argument (onData,onError,onStarted,onStopped,onComplete,onConnectionStateChange).thisroots, browser globals, and any path containingan
endpointssegment (RTK Query).queryKeyand similar) issue no request and areexcluded.
trpc:link:<link>records the literalurlofhttpLink,httpBatchLink,httpBatchStreamLinkandhttpSubscriptionLink.graphql:<type>records named operations:GraphQL header (
($, a directive, or{followed by a field name);OperationDefinitionobjects;loc.source.bodycopy is skipped.Method, callback and factory names were checked against the
@trpc/client11.19 sources (
clientCallTypeMap,TRPCSubscriptionObserver,index.tsexports) and the tRPC 11 React and TanStack documentation.
Documented, not included:
proxy) remain in the recorded path;
useUtils()helpers anduseQueriesare not recognized;Contract and boundary impact
(endpoint findings).
mechanismis afree string and
kindstaysnetwork. New endpoint entries can appear inexisting outputs.
candidates can add application-graph nodes and reconstruction obligations
for recognized procedures.
(AST only; nothing is evaluated).
(
npm run docs:checkpasses).Evidence and regression coverage
Tests added or updated:
src/domain/javascript/javascriptRpcEndpoints.test.ts(10 tests):fetchendpoint.src/domain/webBundleAnalyzer.test.ts: a captured-script case.Base reproduction or other evidence: source-derived. On
ac9677bd,endpoint recognition reads only string-literal
fetch/WebSocket/XHR/.get-style arguments andloadURL, so none of these shapes can produce afinding. The base was not executed against these fixtures.
User-visible output (
analyze_javascript_applicationon a minifiedfixture, via the built stdio server, with the same commit content on base
ac9677bd):navigator.permissions.query,this.client.queryande.queryManager.queryin the same fixture were not reported.Remaining proof gaps:
analyze_web_bundlewas exercised through captured-script unit input, nota live browser.
For evidence-bearing changes:
(
mechanismnames the rule).preserved (locations and module keys as for other endpoints).
visible (documented limitations).
Validation performed
All runs below were on Windows 11 x64 with Node 22.22.3.
On this branch (base
31bfff6f):npm run typecheck: passed.npm run check:fast: passed.npm run verify:test-discovery: discovered all 796 test files exactly once.npm run docs:check: passed.npx vitest run src/domain/javascript/ src/domain/webBundleAnalyzer.test.ts:42 files and 802 tests passed. This includes every existing JavaScript
static-analysis test, so no existing endpoint expectation changed.
Windows source checkout.
analyze_javascript_applicationnow reportscapability_unavailablebecause the Windows native controls manifest(
native/windows/build/manifest.json) is not built in a source checkout.This is unrelated to this change.
On the previous base
ac9677bd, with the same commit content:npm run test:fastshowed no failures beyond those also present on thebase (see feat(mcp): add operator tool selection #1669).
npm run verify:architecture-guards: passed.linear, bounded structure, probed a 23 MB, 600k-node synthetic bundle. The
added work took about 1 s, against about 200 s for the full analysis. This
was not re-measured on the final revision.
Compatibility, safety, and release
endpoint arrays may see new entries for tRPC/GraphQL sources.
browser lane.
Recorded values are procedure names, operation names and literal link URLs,
sanitized like other endpoint candidates.
🤖 Generated with Claude Code