Skip to content

HansKre/sanity-groq-filter

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Sanity GROQ Filter

Curated List of GROQ Filters.

Usage / Examples

Removes all references which are already present in the parent and returns only the unused references.

unusedReferences-Filter

import GroqFilter from "sanity-groq-filter"

export default {
    name: 'documentName',
    type: 'document',
    fields: [
        {
            name: 'fieldName',
            type: 'array',
            of: [
                {
                    type: 'reference',
                    to: { type: 'someReferencedType' },
                    options: { filter: GroqFilter.unusedReferences }
                }
            ],
            validation: Rule => Rule.unique()
        },
    ]
}

matches-Filter

Filters to include only documents with ${fieldName} containing the ${matchStr}.

import GroqFilter from "sanity-groq-filter"

export default {
    name: 'documentName',
    type: 'document',
    fields: [
        {
            name: 'fieldName',
            type: 'array',
            of: [
                {
                    type: 'reference',
                    to: { type: 'someReferencedType' },
                    options: { filter: GroqFilter.matches('myField', 'barbeque') }
                }
            ],
            validation: Rule => Rule.unique()
        },
    ]
}

excludes-Filter

Filters to exclude documents with ${fieldName} containing the ${matchStr}.

import GroqFilter from "sanity-groq-filter"
//...
                    options: { filter: GroqFilter.excludes('myField', 'barbeque') }
//...

Further Reading

Sanity documentation on filters

About

Curated List of GROQ Filters.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages