Skip to content

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

@fcisio

Description

@fcisio

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.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions