This package helps you to reduce boilerplate if you want to create Prisma filter input in Graphql. WhereInput decorator accepts an array of arguments, so you can add all fields with any type as you need.
This package is compatible with all Graphql input types and all classes with InputType decorator. Also you can declare your field input type as array (check the examples below)
You must install class-transformer
package before install if you want to use DecimalFilter
npm -i prisma-nestjs-graphql-filter
yarn add prisma-nestjs-graphql-filter
@WhereInput({ type: String, fields: ['hello', 'world'] })
class ExampleInput {}
NOTE: InputType is not necessary
input ExampleInput {
hello: String
world: String
AND: [ExampleInput]
OR: [ExampleInput]
NOT: [ExampleInput]
}
@WhereInput({ type: ListRelationInput(OtherClass), fields: ['relationField'] })
class ExampleInput {}
NOTE: InputType is not necessary
input ExampleInput {
relationField: OtherClassListRelationWhereInput
AND: [ExampleInput]
OR: [ExampleInput]
NOT: [ExampleInput]
}
input OtherClassListRelationWhereInput {
every: OtherClass
some: OtherClass
none: OtherClass
}
NOTE: This decorator always concat word 'ListRelationWhereInput' to class name and delete words: 'Input' and 'Where' if are present in original input name
@WhereInput(
{ type: [String], fields: ['hello', 'world'] },
{ type: [ListRelationInput(OtherInputClass)], fields: ['relationArray'] }
)
class ExampleInputArray {}
input ExampleInputArray {
hello: [String]
world: [String]
relationField: [StringListRelationWhereInput]
}
Because all fields injected with WhereInput are not declared by the decorator explicitly, Typescript can't recognizes the class fields. To avoid this and helps IDE to hinting, you can extend CastToAbstract
with prisma where type.
For example:
class ExampleInputArray extends CastToAbstract<Prisma.HelloWorldWhereInput>() {}
There are many prisma filter types and extra types availables that you can use as:
- AffectedRows
- BoolFilter
- BoolWithAggregatesFilter
- DateTimeFilter
- DateTimeWithAggregatesFilter
- DecimalFilter
- DecimalWithAggregatesFilter
- FloatFilter
- FloatWithAggregatesFilter
- IntFilter
- IntWithAggregatesFilter
- QueryMode
- SortOrder
- StringFilter
- StringWithAggregatesFilter
- TransactionIsolationLevel