import { GroqBuilder } from "../groq-builder"; import { ExtractProjectionResult, ProjectionMap } from "./projection-types"; import { Fragment } from "../types/public-types"; import { ExtractDocumentTypes, QueryConfig } from "../types/schema-types"; import { RequireAFakeParameterIfThereAreTypeMismatchErrors } from "../types/utils"; declare module "../groq-builder" { interface GroqBuilder { /** * Creates a fragment for any type you specify. * This is useful for inline types that do not have a top-level document type. * * @example * const keyValueFragment = q.fragment<{ key: string, value: number }>().project({ * key: q.string(), * value: q.number(), * }) */ fragment(): FragmentUtil; /** * Creates a fragment for a Document, based on the document type. * * @example * const productFragment = q.fragmentForType<"product">().project(sub => ({ * name: q.string(), * price: q.number(), * images: sub.field("images[]").deref().project({ * width: q.number(), * height: q.number(), * url: q.string(), * }), * })) */ fragmentForType>(): FragmentUtil>; } } /** * When creating a Fragment, we return this utility object * that exposes a `project` method that has almost the same API * as the normal `project` method. */ export type FragmentUtil = { /** * Performs an "object projection", returning an object with the fields specified. * * @param projectionMap - The projection map is an object, mapping field names to projection values * @param __projectionMapTypeMismatchErrors - (internal: this is only used for reporting errors from the projection) */ project, _TProjectionResult = ExtractProjectionResult>(projectionMap: TProjectionMap | ((q: GroqBuilder) => TProjectionMap), ...__projectionMapTypeMismatchErrors: RequireAFakeParameterIfThereAreTypeMismatchErrors<_TProjectionResult>): Fragment; };