You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Typegen doesn't correctly bind function parameters while parsing queries from Typescript/Javascript.
It does attempt to evaluate function expressions contained in a query via string interpolation. It manages this as long as the function only has one "layer" of scope (e.g.: (name) => name), but throws an error if there are any more.
To Reproduce
Run sanity typegen on code with a function like this one:
test('with function with literal parameters',()=>{constsource=` import { groq } from "groq"; const getType = (type) => () => () => type; const query = groq\`*[_type == "\${getType("author")()()}"]\` const res = sanity.fetch(query); `constqueries=findQueriesInSource(source,'test.ts')constqueryResult=queries[0]expect(queryResult?.result).toEqual('*[_type == "author"]')})
Results in an error:
Error: Could not find binding for node "type" in test.ts:3:44 at resolveIdentifier (packages/@sanity/codegen/src/typescript/expressionResolvers.ts:298:9)...
Expected behavior
The query evaluates to *[_type == "author"].
Which versions of Sanity are you using?
3.60.0
@sanity/cli (global) 3.60.0 (up to date)
@sanity/asset-utils 2.0.6 (up to date)
@sanity/eslint-config-studio 4.0.0 (up to date)
@sanity/icons 3.4.0 (up to date)
@sanity/language-filter 4.0.2 (up to date)
@sanity/locale-de-de 1.1.11 (up to date)
@sanity/orderable-document-list 1.2.2 (up to date)
@sanity/ui 2.8.9 (up to date)
@sanity/util 3.60.0 (up to date)
@sanity/vision 3.60.0 (up to date)
sanity 3.60.0 (up to date)
What operating system are you using?
Linux Mint 21.3 Virginia, Kernel 5.15.0-118
Which versions of Node.js / npm are you running?
node 20.18.0
pnpm 9.12.1
(npm 10.9.0 installed)
Additional context
Add any other context about the problem here.
The text was updated successfully, but these errors were encountered:
Describe the bug
Typegen doesn't correctly bind function parameters while parsing queries from Typescript/Javascript.
It does attempt to evaluate function expressions contained in a query via string interpolation. It manages this as long as the function only has one "layer" of scope (e.g.:
(name) => name
), but throws an error if there are any more.To Reproduce
Run sanity typegen on code with a function like this one:
or add as a test alongside the one it's based on
sanity/packages/@sanity/codegen/src/typescript/__tests__/findQueriesInSource.test.ts
Lines 43 to 56 in 12cb46b
Results in an error:
Expected behavior
The query evaluates to
*[_type == "author"]
.Which versions of Sanity are you using?
3.60.0
What operating system are you using?
Linux Mint 21.3 Virginia, Kernel 5.15.0-118
Which versions of Node.js / npm are you running?
node 20.18.0
pnpm 9.12.1
(npm 10.9.0 installed)
Additional context
Add any other context about the problem here.
The text was updated successfully, but these errors were encountered: