0.0.3 • Published 4 years ago
@bytegem/nestjs-graphql-binding-prisma v0.0.3
NestJS GraphQL binding Prisma
NestJS + GraphQL(code first) + Prisma, Help you to implement the Prisma template interface as a GraphQL(code first) Type classes. 🎉Fast work!
Change package to
@bytegem/nest-gql-mix
Installation
Via NPM:
npm i @bytegem/nestjs-graphql-binding-prismaOr via Yarn:
yarn add @bytegem/nestjs-graphql-binding-prismaUsing
Before using this package:
@InputType({ description: 'This is User where input' })
export class UserWhereInput implements Prisma.UserWhereInput {
@Field((type) => [UserWhereInput], { nullable: true })
AND?: UserWhereInput[];
@Field((type) => [UserWhereInput], { nullable: true })
OR?: UserWhereInput[];
@Field((type) => [UserWhereInput], { nullable: true })
NOT?: UserWhereInput[];
@Field((type) => StringFilter, { nullable: true })
id?: StringFilter;
@Field((type) => StringFilter, { nullable: true })
username?: StringFilter;
@Field((type) => StringFilter, { nullable: true })
email?: StringFilter;
@Field((type) => StringFilter, { nullable: true })
phone?: StringFilter;
/// More fields...Now:
@InputTypeBuilder(
{ description: 'User where input' },
FieldsBuilderOptionHelper(
['id', 'username', 'email', 'phone', /* ...more fields */],
() => StringFilter,
{ nullable: true },
),
)
export class UserWhereInput extends InterfaceTransformAbstract<Prisma.UserWhereInput>>() {}
extends InterfaceTransformAbstract<T>()is optional. After adding it, you can prompt the IDE code when you actively use this class. Not inheriting has no effect on the actual operation.
Decorators
ArgsTypeBuilder: TheArgsTypeclass builder.FindFirstArgsBuilder: Fast build Prisma${Model}FindFirstargs class.FindManyArgsBuilder: Fast build Prisma${Model}FindManyargs class.
InputTypeBuilder: TheInputTypeclass builder.WhereInputTypeBuilder: Fast build Prisma${Model}WhereInputinput class.RelationFilterBuilder: Fast build Prisma${Model}ListRelationFilterinput class.
InterfaceTypeBuilder: TheInterfaceTypeclass builder.ObjectTypeBuilder: TheObjectTypeclass builder.
Helpers
FieldsBuilderOptionHelper: Passing Args|Object|Input|InterfaceTypeBuilder parameters does not simplify much code work. For multiple fields with the same FieldOptions, you can use this tool to quickly generate.
Transforms
InterfaceTransformAbstract: You can transform the interface class into an abstract class to help IDE with code hints.
License
The package is MIT License.