Bug Description
The sanity/groq-invalid-type-filter rule incorrectly flags _type filters on array items (discriminated union members) as invalid document types.
Example
Given a schema with object types used as discriminated unions in arrays:
// Object types (NOT document types)
defineType({
name: 'textBlock',
type: 'object',
fields: [{ name: 'text', type: 'text' }],
})
defineType({
name: 'imageBlock',
type: 'object',
fields: [{ name: 'asset', type: 'image' }],
})
// Document type with polymorphic array
defineType({
name: 'post',
type: 'document',
fields: [
{
name: 'content',
type: 'array',
of: [{ type: 'textBlock' }, { type: 'imageBlock' }],
},
],
})
This valid GROQ query:
*[_type == "post"] {
"images": content[_type == "imageBlock"]
}
Produces the error:
Document type "imageBlock" does not exist in schema
Expected Behavior
The rule should distinguish between:
- Document type filters (top-level
*[_type == "..."]) - should be validated against schema document types
- Array item filters (
array[_type == "..."]) - should recognize object types used as discriminated union members
Current Behavior
All _type == "..." filters are validated against document types only, causing false positives for legitimate discriminated union patterns.
Environment
@sanity/eslint-plugin: 0.3.0
@sanity/groq-lint: 0.0.3
Workaround
Currently suppressing with eslint-disable comments, but this masks real issues.
Bug Description
The
sanity/groq-invalid-type-filterrule incorrectly flags_typefilters on array items (discriminated union members) as invalid document types.Example
Given a schema with object types used as discriminated unions in arrays:
This valid GROQ query:
Produces the error:
Expected Behavior
The rule should distinguish between:
*[_type == "..."]) - should be validated against schema document typesarray[_type == "..."]) - should recognize object types used as discriminated union membersCurrent Behavior
All
_type == "..."filters are validated against document types only, causing false positives for legitimate discriminated union patterns.Environment
@sanity/eslint-plugin: 0.3.0@sanity/groq-lint: 0.0.3Workaround
Currently suppressing with eslint-disable comments, but this masks real issues.