Repository navigation
fix(javascript): recover GraphQL operations from exact template text - #1810
jayhemnani9910 wants to merge 7 commits into
Conversation
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: d9acdb41c6
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
dandgabr
left a comment
There was a problem hiding this comment.
Review corrections
- P2 — Preserve GraphQL lexical state and validate skipped interpolations. In
src/domain/javascript/javascriptRpcEndpoints.ts:319-323, the loop restartsskipGraphqlIgnoredfor each quasi and treats any leading interpolation as skippable. If an earlier quasi ends inside a#comment and the interpolation contributes no newline, a later quasi beginning withquery Hiddenis still comment text in the concatenated GraphQL document, but the scanner reports it as an operation. More generally, arbitrary dynamic interpolations are not necessarily fragment definitions. Carry comment state across boundaries and only skip interpolations whose fragment semantics are established; otherwise leave the operation unknown.
|
Thanks, good catch. In 68fb351 the template scan now treats the line an interpolation ends on as unknown, since the interpolation can open or end a Proving each interpolation is a fragment would need binding resolution, and Apollo fragments are usually imported from another module, so a strict check would drop most real cases. I kept it to the line rule for that reason. Happy to tighten it if you'd rather report nothing after a dynamic interpolation. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 68fb351a5e
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
|
@greptileai review |
|
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 1ca2f1e962
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
|
Review findings addressed at their producing boundaries and consumers. Latest changes were reviewed from source; tests and provider runs were skipped at the maintainer's request. Findings requiring separate decisions or verification remain open. The prior scanner resumed after a newline across arbitrary dynamic values, which could change GraphQL comment, block-string or definition context. The template owner now folds exact syntax-level values into one known prefix and stops at the first dynamic boundary. An operation header already observed before that boundary is retained, but later operation-looking text remains unknown; no arbitrary interpolation is assumed to be a fragment. Added and adjusted regressions cover exact ignored prefixes, unresolved prefixes and the existing observed-header/dynamic-suffix behavior. Source inspected at 1ca2f1e; git diff --check passed. Tests, builds, source checks and CI reruns were skipped at the user's explicit request. No passing runtime/provider verification is claimed for this update. The producing template representation now folds exact literal interpolation values before GraphQL interpretation. A fragment/block-string prefix is part of the same document text as the intervening query-looking text; a newline never starts an independent scan across that lexical state. Added the supplied block-string regression. The owner also stops at unresolved dynamic values, retaining only operation headers already visible before them rather than assuming dynamic values are fragments. Source inspected at 1ca2f1e; git diff --check passed. Tests, builds, source checks and CI reruns were skipped at the user's explicit request. No passing runtime/provider verification is claimed for this update. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: ede6c30731
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
|
Review findings addressed at their producing boundaries and consumers. Latest changes were reviewed from source; tests and provider runs were skipped at the maintainer's request. Findings requiring separate decisions or verification remain open. Source fix: The template owner folded an exact child literal but the preorder scan subsequently reported the same literal at its distinct source position. The GraphQL scan now uses one ownership set for text consumed by enclosing representations, covering both compiled-document source bodies and folded template expressions. It marks unwrapped folded literals only after the enclosing template actually reports an operation, preserving independent child observations when the enclosing text has no recognized operation. Added unrun public static-analysis regressions for string, TypeScript-wrapped string, and exact nested-template interpolation, each expecting one endpoint, plus the no-parent-operation case. Source inspection followed preorder traversal and location-keyed finding retention; no downstream value-only deduplication was added. Tests, typechecks, builds, lint, workloads, and CI reruns were not run, as explicitly requested. Source fix: The documentation retained the earlier promise of skipping unresolved fragment identifiers and requiring a later line, while the scanner only has proof for exact literal values. The paragraph now describes exact folding, stopping at unknown interpolation boundaries, retaining an already observed leading header before an unknown suffix, and leaving later operations unknown. It explicitly states that fragment identifiers are not resolved or assumed safe; exact literal prefixes have no special newline requirement. Source inspection compared the scanner branches with the existing unresolved-prefix/comment/block-string coverage and the new reporting-ownership regressions. The unsupported contract is removed without adding speculative binding interpretation. Tests, typechecks, builds, lint, workloads, and CI reruns were not run, as explicitly requested. Source fix: Addressed using the requested contract-removal option. Identifier interpolation has no proven GraphQL lexical value at this boundary, so the scanner conservatively stops rather than assuming the binding is a safe fragment. Removed the documentation promise that this Apollo identifier flow is supported and documented the actual exact-literal behavior, including unknown prefixes and retention of headers already observed before an unknown suffix. Source inspection followed literal admission, unknown-boundary handling, and both JavaScript/web consumers of the shared scanner. Existing unresolved-identifier and lexical-context coverage is retained; no speculative fragment resolver or downstream reparsing was introduced. Tests, typechecks, builds, lint, workloads, and CI reruns were not run, as explicitly requested. Resolving fragment bindings remains outside the advertised contract. Source fix: Folded children and their enclosing template had competing reporting ownership, and location-aware finding keys correctly preserved both. The template now claims the actual unwrapped literal nodes it consumed only when it emits an operation. The existing compiled-document body suppression shares that ownership set, so consumers receive one operation without a second, position-based report or a downstream value-only deduplicator. If no enclosing operation is recognized, independent child observations remain available. Added unrun public static-analysis regressions covering ordinary strings, TypeScript wrappers, exact nested templates, and the no-parent-report case. Source inspection followed producer traversal and finding retention. Tests, typechecks, builds, lint, workloads, and CI reruns were not run, as explicitly requested. |
|
Source fixes and publication evidence for the review findings below. Tests and executable checks were skipped at the maintainer's request. Findings that still require a decision or execution evidence remain open. Root cause: the template owner marked every exact interpolated child as owned after the parent parser emitted only its first operation. Preorder traversal then suppressed a distinct child operation, losing a valid named query or mutation in both JavaScript and web-bundle analysis. Structural fix: the owner now suppresses a folded child only when the child parser's operation value and mechanism match the operation actually emitted by the parent. Distinct operations remain available to consumers; the same ownership rule avoids duplicate findings without downstream value-only deduplication. Source validation: published in PR #1810 at Residuals: runtime/provider behavior and the added regression suite remain unverified under the explicit no-tests scope. |
| }; | ||
| for (const [index, quasi] of node.quasis.entries()) { | ||
| const cooked = quasi.value.cooked; | ||
| if (cooked === undefined || cooked === null) return undefined; |
There was a problem hiding this comment.
A later template segment with no cooked value now discards an operation already found in the prefix. For example, const doc = String.raw followed by `query Q { f } # ${0}\unicode` is valid JavaScript. The invalid escape makes the second segment’s cooked value null, so this loop returns undefined and loses Q. The raw GraphQL text still contains the operation, and the old scanner reported it.
Return report() at this boundary, as for an unresolved interpolation. An uncooked first segment should still remain unknown.
Prompt To Fix With AI
This is a comment left during a code review.
Path: src/domain/javascript/javascriptRpcEndpoints.ts
Line: 339
Comment:
**Known operation disappears**
A later template segment with no cooked value now discards an operation already found in the prefix. For example, `const doc = String.raw` followed by `` `query Q { f } # ${0}\unicode` `` is valid JavaScript. The invalid escape makes the second segment’s cooked value `null`, so this loop returns `undefined` and loses `Q`. The raw GraphQL text still contains the operation, and the old scanner reported it.
Return `report()` at this boundary, as for an unresolved interpolation. An uncooked first segment should still remain unknown.
---
For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 6fb1dcfe40
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| }[] = []; | ||
| const report = (): JavaScriptRpcEndpoint | undefined => { | ||
| const endpoint = graphqlOperationFromText(pieces.join("")); | ||
| if (endpoint !== undefined) |
There was a problem hiding this comment.
Keep commented child literals under the template owner
When a literal interpolation is text inside a comment, for example gql# ${"query Hidden { f }"}``, the folded document has no operation, so this guard does not mark the child as owned; preorder traversal then reaches that StringLiteral and `graphqlOperationFromText` reports `Hidden` in both JavaScript consumers even though the cooked GraphQL contains only comment text. The fresh path left after the earlier comment-state fix is that the apparent operation is the child AST node itself, so use the combined lexical result to keep such children from being independently reinterpreted without suppressing children that are actual definitions.
AGENTS.md reference: AGENTS.md:L19-L19
Useful? React with 👍 / 👎.
6fb1dcf to
a244582
Compare
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: a244582065
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| if (!literal.found) | ||
| // An already observed leading header survives an unknown suffix; | ||
| // never resume scanning after this unresolved boundary. | ||
| return report(); |
There was a problem hiding this comment.
Stop reporting children after unknown interpolation
When a dynamic interpolation precedes a direct literal interpolation containing query Hidden { f }, this early return never records the later expression as owned, so pre-order traversal subsequently reports that StringLiteral on its own. If the dynamic prefix evaluates to # , the combined GraphQL document is entirely comment text, yet both JavaScript and web-bundle analysis claim Hidden; this is a separate post-boundary path from the already-reported exact-comment case because the fresh evidence is a literal after an unresolved expression. Associate later children with the unknown template context instead of independently reinterpreting them.
AGENTS.md reference: AGENTS.md:L19-L19
Useful? React with 👍 / 👎.
| operation: JavaScriptRpcEndpoint | undefined; | ||
| }[] = []; | ||
| const report = (): JavaScriptRpcEndpoint | undefined => { | ||
| const endpoint = graphqlOperationFromText(pieces.join("")); |
There was a problem hiding this comment.
Use GraphQL whitespace rules when folding
When an exact interpolation contributes NBSP (or \v/\f) before the operation, this joined scan passes it to graphqlOperationFromText, whose JavaScript /\s/u predicate accepts those characters even though GraphQL whitespace is limited to tab, space, and CR/LF (with comma and BOM as other ignored tokens). A template with ${"\u00a0"} immediately before query Q { f } therefore newly emits Q although a conforming GraphQL parser rejects the document, polluting both analyzers; use GraphQL's actual ignored-code-point predicate for folded text.
AGENTS.md reference: AGENTS.md:L23-L23
Useful? React with 👍 / 👎.
…tions An interpolation can open or end a `#` comment, so text on the line where it ends is not known to be GraphQL. Only recognize an operation that starts on a later line than the last leading interpolation; otherwise leave the template dynamic.
a244582 to
ee6148e
Compare
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: ee6148e648
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| node: unwrapJavaScriptExpression(expression).node, | ||
| operation: graphqlOperationFromText(text), | ||
| }); | ||
| pieces.push(text); |
There was a problem hiding this comment.
Keep substitutions separate for unproven template tags
When this TemplateLiteral belongs to a user-defined tagged template, JavaScript passes the cooked segments and values separately; it never performs the concatenation done here, and the tag may ignore or reorder the value. For example, const tag = (s) => s[0] + s[1]; tag`que${"ry"} Q { f }` evaluates to que Q { f }, whereas this scan joins query Q { f } and newly reports Q (the previous quasi/child scans report neither chunk). Since inspect handles every template without proving the tag's semantics, fold only untagged templates or proven tag implementations and otherwise retain an unknown boundary.
AGENTS.md reference: AGENTS.md:L19-L19
Useful? React with 👍 / 👎.
Preserve CommonJS literal paths and confined ESM URL semantics, including package main fallback, directory intent, Unicode identity, and present opaque modules. Parse extraction inputs at their AST/source owner, retain skipped HTML and source-map coverage, and distinguish endpoint candidates from proven receiver facts. Version structural fingerprints with computed literal contents and propagate them through worker contracts. Reviewed fixes include #1810, #1840, #2642, #2700, #2702, #2714, #2803, #2960, #2968, #2986, #3035, and #3036. Validation: 158 resolver tests passed; public CLI/MCP module lookup controls, package-main/Unicode workflows, and six builtin workflows passed in the current compiled lane. Worker schema/fingerprint regressions passed. Large public pdf.js completion and real Electron analysis remain unverified.
|
@morluto main has moved and this branch now conflicts. Should I rebase it onto main and run the full test suite on the result, or are you still pushing to it? I'll leave the branch alone until you say. |
|
TL;DR: Head ee6148e passes its own 26 tests on Node 22, 24 and 26. Main af6a998 already finds a query that follows a leading fragment, this PR's first goal. This head chooses to leave that case unknown, so main and the PR now disagree on purpose. I tested the head as pushed. GitHub says it conflicts with main. A text merge of the three files gives 5 conflicts in the source, 1 in the test file and 0 in the docs. What main has and what is leftMain took the first design, in commit b58adaf, which names this PR. It skips quasis that hold only ignored tokens. Then it reads the next one. This head folds only exact literal values and stops at any other interpolation. I ran one fixture through the built CLI on main and on this head. Node 24.18.0 and 26.11.1 gave the same lists.
The last four rows match on both sides. The comment and block string rows hold text that GraphQL treats as hidden. Main reports it. This head does not. The cost is the Apollo rows, which this head drops. Tests
The 3 failures on main are the unknown prefix, comment and block string tests. The 30 on head are mostly tests from later main commits that this branch lacks. The names are in the raw log. I did not check each one by hand. One of them is the leading fragment test. Not run
Thanks, Jay Hemnani, for the report and the fixtures. Jay asked on 2026-10-14 whether to rebase. That question is still open. The call is morluto's. Report the Apollo style, as main does now, or keep it unknown, as this head does. Test setupCommandsEach run sat under nice and systemd-run with MemoryMax=6G. The fixture is one app.js with 13 templates: one fragment definition and one per row above. 🤖 Generated with Claude Code (Sonnet 5.5, verified by Opus 5.5) 🦊 |
|
Main already has the leading-fragment fix in b58adaf, and per @CassieFox23's table it reports every case this PR set out to fix, while this head leaves several of them unknown. Closing this so it doesn't sit in conflict with main. If you want the exact-literal folding from this branch on top of main, say so and I'll open a smaller PR for just that part. |
Summary
A GraphQL document written the way the Apollo Client docs show fragments, with the fragment interpolated before the operation, is not reported as an endpoint:
analyze-javascript-applicationandanalyze-web-bundlereport nographql:queryforCommentsForPost. The same document with the interpolation at the end is reported.No related issue; this is a small follow-up to #1670, so it comes straight as a PR.
Problem and expected behavior
Trigger: a template literal whose text starts with one or more
${...}interpolations, then a named operation.Before: the template branch in
createJavaScriptRpcScanonly reads the first quasi (src/domain/javascript/javascriptRpcEndpoints.ts:312-318). For the document above that quasi is just whitespace, so nothing is found. Modern bundles keep tagged templates as template literals, so this hits shipped code too, not only sources.Expected: leading interpolations hold fragment definitions; the operation that follows them is reported, as it already is when the fragment comes after the operation.
Change and scope
The template branch now walks the quasis in order, skips those that hold only GraphQL ignored tokens (whitespace, commas, comments), and reads the first one with content, using the same header rule as before. The ignored-token loop moves into a small
skipGraphqlIgnoredfunction shared withgraphqlOperationFromText. A template with text before its first interpolation behaves as before, and an uncooked quasi still stops the scan.Not included: operations whose selection set starts with a fragment spread (
query Q { ...F }); the docs already scope that out.Contract and boundary impact
javascriptRpcEndpoints.ts).graphql:*endpoint records, now also for these templates.docs/public/product-catalog.json), package, or installation impact: none.Evidence and regression coverage
recognizes operations that follow leading fragment interpolationsinsrc/domain/javascript/javascriptRpcEndpoints.test.ts(one leading interpolation; two adjacent ones plus a#comment; a negative control with prose before the operation). It fails on current main ([]) and passes with this change.GET_POST_DETAILS,GET_DOG, and a mutation with a trailing fragment):analyze-web-bundlein headless Chrome:GetDogonly before,CommentsForPostandGetDogafter.For evidence-bearing changes:
Validation performed
npx vitest run src/domain/javascript/javascriptRpcEndpoints.test.ts src/domain/webBundleAnalyzer.test.ts: 38 passed; the new case fails without the fix.npx vitest run --project domain src/domain/javascript: 841 passed.npm run check:fast: passed.npx vitest run --project <name>for each project exceptacceptance, afternpm run build:cached, on main 914ba83 before rebasing: 7421 passed, 21 failed, 87 skipped, against 7420 / 21 / 87 on untouched 914ba83 with an identical failure list (firmware tests that need Binwalk 3.1.x, ASAR tests whose unpacked companion file is missing here).acceptancewas not run (out of memory on this machine).Compatibility, safety, and release
analyze-web-bundle.Review checklist
type(scope): outcome.