import { type MaybePromise } from '@pothos/core'; import { type PathSegment } from '@pothos/selection-mapper'; import type { DBQueryConfig, SQL } from 'drizzle-orm'; import type { GraphQLResolveInfo } from 'graphql'; import { type DrizzlePlan } from './adapter.js'; import type { PothosDrizzleSchemaConfig } from './config.js'; import type { SelectionMap } from './selections.js'; export interface QueryFromInfoOptions { config: PothosDrizzleSchemaConfig; context: object; info: GraphQLResolveInfo; typeName?: string; path?: PathSegment[]; paths?: PathSegment[][]; /** Whether the caller will await the query. Async selections otherwise throw. */ awaitSelections?: Await; } /** Only explicitly selected columns are guaranteed; planning metadata is not part of the query. */ export type QueryFromInfoResult = Omit | 'columns'> & { columns: T extends { columns: infer Columns extends {}; } ? Columns : {}; }; /** * The query options returned by `t.drizzleQueryFromInfo`. Branded like the `query` passed to * `t.drizzleField`, so the rows can be returned from a field of the table's type. */ export type DrizzleQueryFromInfoResult = Omit, 'extras'> & { extras: (T extends { extras: infer Extras extends object; } ? Extras : unknown) & { $pothosQueryFor: SQL; }; }; /** A boolean async option must account for promises, just like Prisma's helper. */ export type QueryFromInfoReturn = [Await] extends [false] ? QueryFromInfoResult : MaybePromise>; /** Merge query options with the GraphQL selection and return a query ready for Drizzle. */ export declare function queryFromInfo({ config, context, info, typeName, path, paths, awaitSelections, ...selection }: QueryFromInfoOptions & T & Record | keyof DBQueryConfig<'many'>>, never>): QueryFromInfoReturn; /** * The plan for the field `info` resolves (or `typeName`), nothing recorded: a promise while a * select beneath the field is async, undefined when `paths` are given and nothing is selected * under them. The model loader's, and the first step of a `drizzleField` resolve, whose * merges are recorded so the resolver's `query()` selection can come first. */ export declare function planFromInfo({ config, ...options }: Omit): DrizzlePlan | undefined; /** * The query for a plan `planFromInfo` returned, settled: the caller's `select` first, the walked * plan after it, the mappings recorded, and the query serialized. This is how the `query()` * builder handed to a `drizzleField` or `drizzleConnection` resolver stays synchronous once a * selection beneath the field is async, with the precedence of `queryFromInfo`: a relation the * document also plans with other arguments loads on its own. */ export declare function queryFromPlan(plan: DrizzlePlan | undefined, select?: T): T; //# sourceMappingURL=map-query.d.ts.map