ricokahler / sanity-codegen

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

[v1][client] Error when using snippets/string variables #290

Open madeleineostoja opened 1 year ago

madeleineostoja commented 1 year ago

I'm trying to use query snippets/fragments exported from a shared lib to reduce boilerplate, but the codegen client throws the following error:

Error: Found unsupported source node type "Unknown" in reduceObjectStructures call. Please open an issue.

The basic shape of what I'm trying to do:

fragments.ts

export const asset = groq`'': asset->{url,extension}`;

query.ts

sanity(
  'Home',
  groq`*[_id == "home"][0]{
    ...,
    image {
      ${asset}
    }
  }`
);

Removing the ${...} snippet fixes the issue.

Does the codegen client need to statically analyse the query? Because snippets like this work fine with the standard sanity client (not sure if it's common practice or not, I'm coming from a graphql background and was missing my fragments)