Skip to content

Sanity queries

To make type safe Sanity queries, Fluid uses the GROQD query builder.

The goal of groqd is to give you (most of) the flexibility of GROQ, with the runtime/type safety of Zod and TypeScript

GROQD is obviously more verbose than pure GROQ queries, but it makes it very convenient to get fully type safe data from Sanity.

// The following GROQD query
q("*[_type == 'pokemon']", { isArray: true })
.grab({
name: q.string(),
})
// Translates to
[_type == 'pokemon']

You can learn how to build GROQD queries here.

GROQD comes with useful utilities such as InferType and TypeFromSelection to easily infer types from your queries/fragments.