import { GraphQLFieldResolver, GraphQLScalarType } from 'graphql'; import * as Nexus from 'nexus'; import { DynamicOutputPropertyDef } from 'nexus/dist/dynamicProperty'; import { DmmfDocument, InternalDMMF } from './dmmf'; import { OnUnknownArgName, OnUnknownFieldName, OnUnknownFieldType, OnUnknownPrismaModelName } from './hooks'; import { ArgsNamingStrategy, FieldNamingStrategy, OperationName } from './naming-strategies'; import { PaginationStrategyTypes } from './pagination'; import { Publisher } from './publisher'; import * as Typegen from './typegen'; import { GlobalComputedInputs, Index, LocalComputedInputs } from './utils'; interface FieldPublisherConfig { alias?: string; type?: string; pagination?: boolean | Record; filtering?: boolean | Record; ordering?: boolean | Record; computedInputs?: LocalComputedInputs; resolve?: (root: object, args: object, ctx: object, info: object, originalResolve: GraphQLFieldResolver) => Promise; } type WithRequiredKeys = Omit & Required>; type ResolvedFieldPublisherConfig = Omit, 'computedInputs'> & { locallyComputedInputs: LocalComputedInputs; }; type PublisherConfigData = { field: InternalDMMF.SchemaField; givenConfig?: FieldPublisherConfig; }; type FieldConfigData = { field: InternalDMMF.SchemaField; publisherConfig: ResolvedFieldPublisherConfig; typeName: string; operation?: OperationName | null; resolve?: Nexus.FieldResolver; }; type PrismaClientFetcher = (ctx: Nexus.core.GetGen<'context'>) => any; export interface Options { /** * nexus-prisma will call this to get a reference to an instance of the Prisma Client. * The function is passed the context object. Typically a Prisma Client instance will * be available on the context to support your custom resolvers. Therefore the * default getter returns `ctx.prisma`. */ prismaClient?: PrismaClientFetcher; /** * Same purpose as for that used in `Nexus.makeSchema`. Follows the same rules * and permits the same environment variables. This configuration will completely * go away once Nexus has typeGen plugin support. */ shouldGenerateArtifacts?: boolean; inputs?: { /** * Path to your generated Prisma Client. For Prisma 7+ with `prisma-client` generator, * this should match the `output` field in your schema.prisma generator block. * * @default './src/generated/prisma' * * @example * // In schema.prisma: * // generator client { * // provider = "prisma-client" * // output = "./src/generated/prisma" * // } * * // In nexus config: * nexusPrisma({ * inputs: { * prismaClient: './src/generated/prisma' * } * }) */ prismaClient?: string; /** * Absolute or relative path to your `schema.prisma` file. Used to load the DMMF * via `@prisma/internals` `getDMMF` for Prisma 7+ with the `prisma-client` generator. * * If omitted, the plugin will fall back to the `PRISMA_SCHEMA_PATH` environment variable * and then to the common locations `./prisma/schema.prisma` and `./schema.prisma` * relative to `process.cwd()`. */ prismaSchema?: string; }; outputs?: { /** * Where should nexus-prisma put its typegen on disk? * * @default 'node_modules/@types/typegen-nexus-plugin-prisma/index.d.ts' * * @remarks * * This configuration will completely go away once Nexus has typeGen plugin * support. * */ typegen?: string; }; /** * Select the pagination strategy. * * 'prisma' strategy results in GraphQL pagination arguments mirroring those of Prisma: skip, cursor, take * * 'relay' strategy results in GraphQL pagination arguments matching those of the [GraphQL Relay specification](https://relay.dev/graphql/connections.htm): before, after, first, last. * * @default 'relay' */ paginationStrategy?: 'relay' | 'prisma'; /** * Enable experimental CRUD capabilities. * Add a `t.crud` method in your definition block to generate CRUD resolvers in your `Query` and `Mutation` GraphQL Object Type. * * @default false */ experimentalCRUD?: boolean; /** * Map of GraphQL scalar types to be used by the library for the Prisma scalars * * When not provided, the scalar types will be passthrough. * * @default {} */ scalars?: Partial, GraphQLScalarType>>; computedInputs?: GlobalComputedInputs; /** * Enable atomic operations * * @remarks * * GraphQL [doesn't support union input types](https://github.com/graphql/graphql-spec/pull/733). But Prisma Client atomic operations (e.g. [atomic operations on update for Int and Float fields](https://www.prisma.io/docs/reference/tools-and-interfaces/prisma-client/crud#atomic-operations-on-update)) are modelled as a union input type in TypeScript. By default Nexus Prisma will model this as a nested input object type with runtime validation that only one operation is sent by the client. However, you can configure this. If your API clients do not need the power of all the atomic operations then disable them. When disabled the nested input object is replaced by only one of the possible atomic operations. Disabling removes types from your API schema and thus complexity for your clients. * * @default true */ atomicOperations?: boolean; } export interface InternalOptions extends Options { dmmf?: DmmfDocument; nexusBuilder: Nexus.PluginBuilderLens; nexusPrismaImportId?: string; onUnknownFieldName?: OnUnknownFieldName; onUnknownFieldType?: OnUnknownFieldType; onUnknownArgName?: OnUnknownArgName; onUnknownPrismaModelName?: OnUnknownPrismaModelName; } export interface InternalPublicOptions extends Omit { } export declare function build(options: InternalOptions): { types: (DynamicOutputPropertyDef<"crud"> | DynamicOutputPropertyDef<"model">)[]; wasCrudUsedButDisabled(): boolean; }; export interface CustomInputArg { arg: InternalDMMF.SchemaArg; type: InternalDMMF.InputType | InternalDMMF.SchemaEnum | { name: string; }; } export declare class SchemaBuilder { options: InternalOptions; readonly dmmf: DmmfDocument; protected argsNamingStrategy: ArgsNamingStrategy; protected fieldNamingStrategy: FieldNamingStrategy; protected paginationStrategy: PaginationStrategyTypes; protected getPrismaClient: PrismaClientFetcher; protected publisher: Publisher; protected scalars: Record; protected globallyComputedInputs: GlobalComputedInputs; protected unknownFieldsByModel: Index; wasCrudUsedButDisabled: boolean; constructor(options: InternalOptions); /** * The build entrypoint, bringing together sub-builders. */ build(): (DynamicOutputPropertyDef<"crud"> | DynamicOutputPropertyDef<"model">)[]; /** * Build `t.crud` dynamic output property */ protected buildCRUD(): DynamicOutputPropertyDef<'crud'>; protected buildDisabledCRUD(): DynamicOutputPropertyDef<'crud'>; /** * Build the `t.model` dynamic output property. */ protected buildModel(): DynamicOutputPropertyDef<"model">; protected internalBuildModel(typeName: string, t: Nexus.core.OutputDefinitionBlock, stage: Nexus.core.OutputFactoryConfig['stage']): any; buildPublisherConfig({ field, givenConfig: { computedInputs, ...otherConfig }, }: Required): ResolvedFieldPublisherConfig; buildFieldConfig(config: FieldConfigData): Nexus.core.NexusOutputFieldConfig; buildArgsFromField(config: FieldConfigData): Nexus.core.ArgsRecord; determineArgs(config: FieldConfigData): CustomInputArg[]; argsFromMutationField({ publisherConfig, field }: FieldConfigData): CustomInputArg[]; protected argsFromQueryOrModelField({ typeName, field, publisherConfig }: FieldConfigData): CustomInputArg[]; /** * This handles "tailored field feature publishing". * * With tailored field feature publishing, users can specify that only some * fields of the PSL model are exposed under the given field feature. For * example, in the following... * * ```ts * t.model.friends({ filtering: { firstName: true, location: true } }) * ``` * * ...the field feature is "filtering" and the user has tailored it so that * only "firstName" and "location" of the field's type (e.g. "User") are * exposed to filtering on this field. So the resulting GQL TypeDef would look * something like: * * ```ts * ... * friends(where: { firstName: ..., location: ..., }): [User] * ... * ``` */ protected handleInputObjectCustomization(params: { fieldWhitelist: Record | boolean; inputTypeName: string; fieldName: string; graphQLTypeName: string; isWhereType: boolean; }): InternalDMMF.InputType; protected assertOutputTypeIsDefined(typeName: string, fieldName: string, outputType: string, stage: 'walk' | 'build'): boolean; protected assertArgNameExists(parentTypeName: string, prismaOutputTypeName: string, fieldName: string, config: FieldPublisherConfig, stage: 'build' | 'walk', configProperty: 'filtering' | 'ordering'): { wrongArgNames: string[]; } | true; protected assertFilteringOrOrderingArgNameExists(parentTypeName: string, prismaOutputTypeName: string, fieldName: string, config: FieldPublisherConfig, stage: 'build' | 'walk'): void; } export {}; //# sourceMappingURL=builder.d.ts.map