ricokahler / sanity-codegen

Generate TypeScript types from your Sanity.io schemas
sanity-codegen-dev.vercel.app
MIT License
270 stars 19 forks source link

Found 0 candidate files #296

Open philefstat opened 1 year ago

philefstat commented 1 year ago

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?

MurmeltierS commented 1 year ago

can you share your sanity.config.ts?

oppodeldoc commented 1 year ago

@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!