sanity-io / sanity

Sanity Studio – Rapidly configure content workspaces powered by structured content
https://www.sanity.io
MIT License
5.28k stars 427 forks source link

[Sanity Typegen]: Support wild-card (*) imports when constructing queries #7418

Open r0skar opened 2 months ago

r0skar commented 2 months ago

Describe the bug

I am not a 100% sure if this qualifies as a bug report or if it should be a feature request. Currently, we can not use a wild-card (*) import to import fragments of a query.

To Reproduce

Steps to reproduce the behavior:

  1. Create a new file query.ts
import * as F from "./fragments";

export const getSite = groq`*[_type == "site"][0]{
  name,
  "seoMetadata": seoMetadata${F.SEO_META_DATA_FRAGMENT},
}`;
  1. Run typegen.
  2. Typegen throws an error.
❌ Unsupported expression type: MemberExpression in lib/sanity/queries.ts:8:30 in "lib/sanity/queries.ts"

Expected behavior

Types should be generated.

Which versions of Sanity are you using?

@sanity/cli (global)  3.55.0 (up to date)
@sanity/types         3.55.0 (up to date)
@sanity/vision        3.55.0 (up to date)
sanity                3.55.0 (up to date)

Additional context

This works as expected:

import { SEO_META_DATA_FRAGMENT } from "./fragments";

export const getSite = groq`*[_type == "site"][0]{
  name,
  "seoMetadata": seoMetadata${SEO_META_DATA_FRAGMENT},
}`;
dogfrogfog commented 1 month ago

experiencing the issue right now