Simple and flat inputs
In version 2.6.0, Prisma released atomicNumberOperations
preview feature that allows you to update scalar fields without checking the current value, e.g. increment or decrement a number value.
However, GraphQL does not support input unions, hence it's not possible to support both simple scalar fields and atomic operation inputs at the same time. So, if you prefer simplicity over more complex approach using nested inputs, you can provide the useSimpleInputs
generator option:
generator typegraphql {
provider = "typegraphql-prisma"
output = "../prisma/generated/type-graphql"
useSimpleInputs = true
}
By using this option, instead of generating nested inputs with IntFieldUpdateOperationsInput
or StringFieldUpdateOperationsInput
as a field type, it will emit much simpler version of inputs for update operations - with just scalar values:
- useSimpleInputs = true
- useSimpleInputs = false
@TypeGraphQL.InputType("CategoryUpdateInput", {})
export class CategoryUpdateInput {
@TypeGraphQL.Field(_type => String, {
nullable: true,
})
name?: string | undefined;
@TypeGraphQL.Field(_type => String, {
nullable: true,
})
slug?: string | undefined;
@TypeGraphQL.Field(_type => TypeGraphQL.Int, {
nullable: true,
})
number?: number | undefined;
}
@TypeGraphQL.InputType("CategoryUpdateInput", {})
export class CategoryUpdateInput {
@TypeGraphQL.Field(_type => StringFieldUpdateOperationsInput, {
nullable: true,
})
name?: StringFieldUpdateOperationsInput | undefined;
@TypeGraphQL.Field(_type => StringFieldUpdateOperationsInput, {
nullable: true,
})
slug?: StringFieldUpdateOperationsInput | undefined;
@TypeGraphQL.Field(_type => IntFieldUpdateOperationsInput, {
nullable: true,
})
number?: IntFieldUpdateOperationsInput | undefined;
}
Same goes to array fields and nested documents, when you're using MongoDB as your Prisma db provider.
By using this option, instead of generating nested inputs with XYZEnvelopeInput
or FooCreateBarInput
as a field type, it will emit much simpler version of inputs:
- useSimpleInputs = true
- useSimpleInputs = false
@TypeGraphQL.InputType("UserUpdateInput", {})
export class UserUpdateInput {
@TypeGraphQL.Field(_type => [TypeGraphQL.Int], {
nullable: true,
})
luckyNumbers?: number[] | undefined;
@TypeGraphQL.Field(_type => UserAddressCreateInput, {
nullable: true,
})
address?: UserAddressCreateInput | undefined;
}
@TypeGraphQL.InputType("UserUpdateInput", {})
export class UserUpdateInput {
@TypeGraphQL.Field(_type => UserCreateluckyNumbersInput, {
nullable: true,
})
luckyNumbers?: UserCreateluckyNumbersInput | undefined;
@TypeGraphQL.Field(_type => UserAddressUpdateEnvelopeInput, {
nullable: true,
})
address?: UserAddressUpdateEnvelopeInput | undefined;
}