Skip to content

feat(javascript): recognize tRPC procedures and GraphQL operations - #1670

Merged
morluto merged 4 commits into
morluto:mainfrom
pompiliodonatoapp:feat/rpc-endpoint-recognition
Oct 11, 2026
Merged

morluto merged 4 commits into
morluto:mainfrom
pompiliodonatoapp:feat/rpc-endpoint-recognition

Conversation

@pompiliodonatoapp

Copy link
Copy Markdown
Contributor

Summary

Static analysis records RPC client syntax as network endpoint candidates in
both analyze_javascript_application and analyze_web_bundle. Before this
change, tRPC and GraphQL clients contributed no endpoints, because the calls
are not string-literal fetch/XHR/WebSocket arguments. No existing issue is
linked; this is proposed as an enhancement.

Problem and expected behavior

In a minified tRPC client, e.invoice.list.useQuery({...}) and
n.empresa.byCnpj.query(...) name server procedures that a feature trace
needs, and so do GraphQL documents such as
query ListarNotas($competencia: String!) { ... }. Expected: these appear as
endpoint candidates with an explicit mechanism, without turning Apollo, RxJS,
store or browser APIs into false procedures.

Change and scope

src/domain/javascript/javascriptRpcEndpoints.ts is a per-source pre-order
scan, used by both analyzers.

  • trpc:procedure:<method> records the static member path of
    root.<path>.<method>(...).
    • Hooks and TanStack option factories are recognized directly.
    • query/mutate need a root bound to
      createTRPCClient/createTRPCProxyClient, or a tRPC source marker
      (TRPCClientError, trpc-accept, /trpc) together with a path of at
      least two segments.
    • subscribe needs the marker plus a tRPC observer argument (onData,
      onError, onStarted, onStopped, onComplete,
      onConnectionStateChange).
    • Never procedures: this roots, browser globals, and any path containing
      an endpoints segment (RTK Query).
    • Cache-key helpers (queryKey and similar) issue no request and are
      excluded.
  • trpc:link:<link> records the literal url of httpLink,
    httpBatchLink, httpBatchStreamLink and httpSubscriptionLink.
  • graphql:<type> records named operations:
    • from string and cooked template literals, when the header is a valid
      GraphQL header (($, a directive, or { followed by a field name);
    • from precompiled OperationDefinition objects;
    • a graphql-tag loc.source.body copy is skipped.

Method, callback and factory names were checked against the @trpc/client
11.19 sources (clientCallTypeMap, TRPCSubscriptionObserver, index.ts
exports) and the tRPC 11 React and TanStack documentation.

Documented, not included:

  • leading carrier segments (webpack module bindings, properties holding the
    proxy) remain in the recorded path;
  • useUtils() helpers and useQueries are not recognized;
  • links whose callee name was renamed by a minifier are not recognized.

Contract and boundary impact

  • Semantic owner and earliest changed stage: domain static analysis
    (endpoint findings).
  • CLI and MCP/tool-catalog contract: no schema change. mechanism is a
    free string and kind stays network. New endpoint entries can appear in
    existing outputs.
  • Provider, bridge, target-format, or platform compatibility: none.
  • Evidence, artifact, provenance, or reconstruction contract: new endpoint
    candidates can add application-graph nodes and reconstruction obligations
    for recognized procedures.
  • Process execution, authorization, cleanup, or containment impact: none
    (AST only; nothing is evaluated).
  • Generated metadata, package, or installation impact: none
    (npm run docs:check passes).

Evidence and regression coverage

  • Tests added or updated:

    • src/domain/javascript/javascriptRpcEndpoints.test.ts (10 tests):
      • hooks on renamed roots; TanStack factories; bound vanilla clients;
      • marker plus segment rules; subscription observers;
      • Apollo, RxJS, store, RTK Query and browser-global negatives;
      • GraphQL text and documents; prose and i18n negatives;
      • graphql-tag deduplication; an unchanged fetch endpoint.
    • 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 and loadURL, so none of these shapes can produce a
    finding. The base was not executed against these fixtures.

  • User-visible output (analyze_javascript_application on a minified
    fixture, via the built stdio server, with the same commit content on base
    ac9677bd):

    {"endpoint_kind":"network","value":"/api/trpc","mechanism":"trpc:link:httpBatchLink"}
    {"endpoint_kind":"network","value":"invoice.list","mechanism":"trpc:procedure:useQuery"}
    {"endpoint_kind":"network","value":"invoice.create","mechanism":"trpc:procedure:useMutation"}
    {"endpoint_kind":"network","value":"empresa.byCnpj","mechanism":"trpc:procedure:query"}
    {"endpoint_kind":"network","value":"ListarNotas","mechanism":"graphql:query"}
    {"endpoint_kind":"network","value":"EmitirNota","mechanism":"graphql:mutation"}
    {"endpoint_kind":"network","value":"/api/health","mechanism":"call:fetch"}
    

    navigator.permissions.query, this.client.query and
    e.queryManager.query in the same fixture were not reported.

  • Remaining proof gaps:

    • precision was not measured on a corpus of production bundles;
    • analyze_web_bundle was exercised through captured-script unit input, not
      a live browser.

For evidence-bearing changes:

  • Observed, derived, and inferred claims remain distinguishable
    (mechanism names the rule).
  • Artifact identity, source provenance, and failed attempts remain
    preserved (locations and module keys as for other endpoints).
  • Unsupported, incomplete, unavailable, or uncertain outcomes remain
    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.
  • The end-to-end fixture analysis could not be repeated on this base from a
    Windows source checkout. analyze_javascript_application now reports
    capability_unavailable because 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:

  • The end-to-end analysis above passed.
  • npm run test:fast showed no failures beyond those also present on the
    base (see feat(mcp): add operator tool selection #1669).
  • npm run verify:architecture-guards: passed.
  • An independent review of an earlier revision of this scan, with the same
    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

  • Breaking changes or migration steps: none. Consumers asserting exact
    endpoint arrays may see new entries for tRPC/GraphQL sources.
  • Real Hopper/Ghidra, browser, or OS coverage: Windows 11 only; no live
    browser lane.
  • Package or release metadata impact: none.
  • Security, privacy, process, or containment review: syntax only.
    Recorded values are procedure names, operation names and literal link URLs,
    sanitized like other endpoint candidates.

🤖 Generated with Claude Code

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]>
@chatgpt-codex-connector

Copy link
Copy Markdown

Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits.
Repo admins can enable using credits for code reviews in their settings.

@morluto
morluto merged commit 3a7a307 into morluto:main Oct 11, 2026
28 of 29 checks passed
@CassieFox23

Copy link
Copy Markdown
Contributor

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

Check Node 22.23.1 Node 24.18.0 Node 26.11.1
The PR's 2 test files on main (37 tests) 37 pass 37 pass 37 pass

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.

What the source has Real Plain Minified (3 ways)
React hooks: 6 procedures, nested up to 3 deep 6 6 6, 6, 6
Three nested-router hooks 3 3 3, 3, 3
TanStack option factories (and a skipped queryKey) 2 2 2, 2, 2
Vanilla client: 4 procedures and a link URL 5 5 3, 3, 3
Alias const t = client; t.x.y.query(), a direct call, a link 4 4 3, 3, 3
Client made in one file, used in another 3 1 0, 0, 0
useUtils() and useQueries calls (not recognized, as the PR says) 1 0 0, 0, 0
GraphQL gql templates (query, mutation, subscription) 4 4 4, 4, 4
GraphQL strings in client.query, client.mutate, a fetch body 3 3 3, 3, 3
Precompiled OperationDefinition object 1 1 1, 1, 1
Odd shapes: @live, two operations in one document 4 3 3, 3, 3

A procedure whose first name is top, history, location, screen, document or performance is dropped, even on a client made by createTRPCClient. A router named invoice.history is fine.

Why the other misses happen

The minifier renames httpBatchLink and createTRPCClient. The link URL and a one-segment client.stats.query() need those names. The PR documents the renamed link.

  • Alias t.x.y.query() was found only because the file also holds the text /trpc and the path has two segments. A one-segment alias, or an alias in a file without that text, was not found.
  • Only the first operation of one gql document is reported.
  • The browser-global drop comes from the list in javascriptRpcEndpoints.ts. It checks the first name of the path.

False positives

Case Reported
Plain objects: a.b.query(), knex("t").where().query(), db.users.query(...), store.cart.mutate(...) 0
Six non-GraphQL strings, some tagged gql 0
Apollo-style .query, RTK endpoints, navigator.permissions.query, RxJS subscribe 0
A file with the text /trpc and an unrelated store.cart.items.mutate(...) 1 wrong (cart.items)
Made-up roots tsr, orpc, swr with .useQuery or .queryOptions 3 reported as tRPC

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 /trpc plus a path of two segments. It did not appear after terser or in the bundle, because the minifier dropped the unused /trpc string.

Real app: create-t3-app (MIT), commit 4709861f7. I took its example post.tsx and react.tsx. I ran them as source, as a bundle with the real tRPC and TanStack packages, and as a minified bundle. All three gave post.getLatest and post.create, which is what the source calls. The link URL is built at run time, so no link was reported, as the PR says. Before the merge, all three gave 0.

Not run

  • analyze-web-bundle on a live page. It needs a browser target, and I started none. Only the PR's unit test for it ran.
  • Windows and macOS. The wider checks: type check, check:fast, docs:check, the full suite.
  • Precision on a large set of production bundles.
  • A real GraphQL client bundle with named operations. I tried graphiql 5.4.0 (MIT). It has none, and gave 0 on both commits.

Thanks, pompiliodonatoapp, for the feature and for the tests.

Test setup
  • Box: Nobara 44 (Fedora 44 base), Linux 7.2.9
  • CPU: AMD Ryzen 9 5900X, 12 cores / 24 threads
  • RAM: 32 GB DDR4-3600
  • Node: 22.23.1, 24.18.0, 26.11.1
  • Main: 17f7040
  • Base: 83e5255
  • Tools: terser 5.51.2 (BSD-2-Clause), esbuild 0.28.2 (MIT)
  • Bundled from npm (MIT): @trpc/client 11.19.0, @trpc/react-query 11.19.0
  • Bundled from npm (MIT): superjson 2.2.6
  • Bundled from npm (MIT): @tanstack/react-query 5.104.1
  • Bundled from npm (MIT): graphql-tag 2.12.7, graphql 17.0.2
Commands
npm ci && npm run build && npm run test:prepare
npm run test:local -- src/domain/javascript/javascriptRpcEndpoints.test.ts src/domain/webBundleAnalyzer.test.ts
node scripts/rea.mjs analyze-javascript-application <dir> --artifact-format directory --json
terser app.js --module -c -m -o out.js
esbuild app.js --minify --format=esm --outfile=out.js
esbuild app.js --bundle --minify --format=esm --platform=browser --outfile=out.js

🤖 Generated with Claude Code (Sonnet 5.5, verified by Opus 5.5) 🦊

@morluto

morluto commented Oct 11, 2026

Copy link
Copy Markdown
Owner

Thank you, @pompiliodonatoapp, for teaching the analyzers to recognize tRPC procedures and named GraphQL operations. Those are useful leads that literal fetch detection misses. I also appreciate the tests separating tRPC patterns from unrelated query and subscribe calls. Welcome to the project!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: native Native analysis and decompilation, including Ghidra, IDA, and Hopper analysis behavior enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants