Skip to content
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

[TypeGen]: Allow more "ignore" flexibility #8078

Open
fcisio opened this issue Dec 16, 2024 · 1 comment
Open

[TypeGen]: Allow more "ignore" flexibility #8078

fcisio opened this issue Dec 16, 2024 · 1 comment
Assignees
Labels
feature-request typegen Issues related to TypeScript types generation

Comments

@fcisio
Copy link

fcisio commented Dec 16, 2024

Is your feature request related to a problem? Please describe.

It is currently possible to ignore entire individual queries:

// this query won't get generated types because of the instruction below
// @sanity-typegen-ignore
const anotherQuery = groq`*[_type == "another"][0]`

My problem is that the only time I want to ignore something, it is parts of a query, not the query itself.

For example, here I query some modules. Then I query those same modules through a reference.
I do not need or want typegen for that second layer (it add a LOT of time to the generation process).

export const BASE_MODULES_FRAGMENT = /* groq */ `
  _key,
  _type,
  _type == 'a' => { ... },
  _type == 'b' => { ... },
  _type == 'c' => { ... },
`

export const MODULES_FRAGMENT = /* groq */ `
  ${BASE_MODULES_FRAGMENT},
  _type == 'reusable-modules' => {
    "modules": reference->modules[] { ${BASE_MODULES_FRAGMENT} }
  },
`

Describe the solution you'd like

The generator could check within the queries for:
A. Comment
B. Key
C. Object

export const MODULES_FRAGMENT = /* groq */ `
  ${BASE_MODULES_FRAGMENT},

  // @sanity-typegen-ignore
  _type == 'reusable-modules' => {
    "modules": reference->modules[] { ${BASE_MODULES_FRAGMENT} }
  },

  "@sanity-typegen-ignore": "",
  _type == 'reusable-modules' => {
    "modules": reference->modules[] { ${BASE_MODULES_FRAGMENT} }
  },

  "@sanity-typegen-ignore": {
    _type == 'reusable-modules' => {
      "modules": reference->modules[] { ${BASE_MODULES_FRAGMENT} }
    },
  },
`

Describe alternatives you've considered

Apart from splitting a query into multiple parts, which is not always possible, I don't think an alternative exists.

@sgulseth sgulseth added typegen Issues related to TypeScript types generation feature-request labels Dec 19, 2024
@sgulseth
Copy link
Member

Thanks for the request! TypeGen relies on the groq-js' GROQ parser, and atm comments are stripped during parsing. However this is something we want to support as it also unlock other features like formatting etc, but it's not a quick fix unfortunately

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature-request typegen Issues related to TypeScript types generation
Projects
None yet
Development

No branches or pull requests

2 participants