-
Notifications
You must be signed in to change notification settings - Fork 398
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
CLI Typegen doesn't work with imported partial queries #6297
Comments
I am facing a similar issue to this, but the error message I get is: ✖ Could not find binding for import "useLocale" in next-intl in "../src/app/[locale]/trails/page.tsx" This is the relevant code from my import { groq } from 'next-sanity';
import { useLocale } from 'next-intl';
export default async function Trails() {
const locale = useLocale();
const TRAILS_QUERY = groq`*[_type == "trail" && language == "${locale}"]{
_id,
name
}`; I need the |
Hey, in your case that is a different issue, you should be using prepared queries, so you would not be concatenating strings at all, you would send the locale param as a second argument example sanityClient.fetch(
`*[_type == "orders" && orderId.current == $orderId][0]{...}`,
{orderId: query.orderId}
) |
Thanks, and it's working for me now. Concatenation was working for me to get the data so I assumed that the issue was with |
#6457 Does not seems to fix all cases still getting |
@georgeosutton Do you have a reproduction either in a repo or a gist somewhere? |
I've added a folder with relevant fragments / query. I get the following when I run
|
Thanks a lot! I have a fix lined up here #6540 |
fix for this was released yesterday, v3.41.0 |
Describe the bug
When using groq typegen
sanity schema extract && sanity typegen generate
it is perfectly able to work with queries that are composed out of concatenated string variables. It, however doesn't work, crashes, if any of the variables are imported from another file.To Reproduce
Create 2 files -
repo.ts
andutil.ts
Place the following query into the
repo.ts
:Place the following query segment into the
util.ts
file:Run the typegen command:
sanity schema extract && sanity typegen generate
It will crash with an error, saying that it
✖ Cannot find module './util'
Expected behavior
It should behave the same as it does when the inner variable is within the same file as the query - successfully compose the query and its type.
Which versions of Sanity are you using?
What operating system are you using?
macOS Sonoma
Which versions of Node.js / npm are you running?
The text was updated successfully, but these errors were encountered: