UNPKG

groq-builder

Version:

A **schema-aware**, strongly-typed GROQ query builder. It enables you to build GROQ queries using **auto-completion**, **type-checking**, and **runtime validation**.

31 lines (30 loc) 1.17 kB
import { ExtractRefType } from "../types/schema-types"; import { ResultItem } from "../types/result-types"; declare module "../groq-builder" { interface GroqBuilder<TResult, TQueryConfig> { /** * Uses GROQ's dereference operator (`->`) to follow a reference. * * @example * q.star * .filterByType("product") * .field("image").deref().field("url") * // GROQ: *[_type == "product"].image->url * * @example * q.star.filterByType("product").project(sub => ({ * category: sub.field("category").deref().field("title"), * images: sub.field("images[]").deref().project({ * url: q.string(), * width: q.number(), * height: q.number(), * }), * })) * // GROQ: *[_type == "product"]{ * // "category": category->title, * // "images": images[]->{ url, width, height } * // } */ deref<TReferencedType = ExtractRefType<ResultItem.Infer<TResult>, TQueryConfig>>(): GroqBuilder<ResultItem.Override<TResult, TReferencedType>, TQueryConfig>; } }