sanity-codegen
sanity-codegen copied to clipboard
Found 0 candidate files
I've both the main version and v1 alpha, but no matter what I try, I get
ℹ [default] Found 0 candidate files
⚠ [default] Found 0 queries from 0 files.
Even with a simple groq query in a typescript file:
groq`*[_type == "siteSettings"][0]{
title,
description
}`
I've also tried wrapping it in codegen
as follows:
import { codegen, groq } from '@sanity-codegen/client'
const query = codegen(
// the query key:
'SiteSettings',
// the query (must be wrapped in groq``):
groq`*[_type == "siteSettings"][0]{
title,
description
}`
)
but I get the same result. How does sanity-codegen find queries / how can I point it in the direction of my queries so that the types are generated for them?
can you share your sanity.config.ts?
@philefstat or anyone else who runs into this: I'm using this with NextJS 13 and the app
directory, but sanity-codegen looks in src
by default. The fix for me was to use the include
option in the sanity-codegen.config.ts
file. My config now looks like this:
import { SanityCodegenConfig } from '@sanity-codegen/cli'
const config: SanityCodegenConfig = {
sanityConfigPath: './sanity.config.ts',
output: 'types/sanity-codegen/sanity-codegen.d.ts',
include: ['./app/**/*.{js,jsx,ts,tsx}'],
}
export default config
I'm getting queries autogenerated now. Great work @ricokahler !
It's in the docs but kind of snuck up on me. Hope this helps!