diff --git a/src/Category/category.schema.ts b/src/Category/category.schema.ts index d65225e..eb3c5ae 100644 --- a/src/Category/category.schema.ts +++ b/src/Category/category.schema.ts @@ -55,5 +55,38 @@ export class CategorySchema extends PothosSchema { }, }), })); + + // mutation + this.builder.mutationFields((t) => ({ + createCategory: t.prismaField({ + type: this.category(), + args: { + input: t.arg({ + type: this.builder.generator.getCreateInput('Category'), + required: true, + }), + }, + resolve: async (query, root, args, ctx, info) => { + return await this.prisma.category.create({ + data: args.input, + }); + }, + }), + createManyCategories: t.prismaField({ + type: [this.category()], + args: { + data: t.arg({ + type: [this.builder.generator.getCreateManyInput('Category')], + required: true, + }), + }, + resolve: async (query, root, args, ctx, info) => { + return await this.prisma.category.createManyAndReturn({ + data: args.data, + skipDuplicates: true, + }); + }, + }), + })); } } diff --git a/src/Graphql/graphql.generator.ts b/src/Graphql/graphql.generator.ts index b0c82e8..56aed6d 100644 --- a/src/Graphql/graphql.generator.ts +++ b/src/Graphql/graphql.generator.ts @@ -14,7 +14,7 @@ import * as Prisma from '@prisma/client'; import { SchemaBuilderToken } from '@smatch-corp/nestjs-pothos'; // -const filterOps = ['equals', 'in', 'notIn', 'not', 'is', 'isNot'] as const; +const filterOps = ['equals', 'in', 'notIn', 'not', 'is'] as const; const sortableFilterProps = ['lt', 'lte', 'gt', 'gte'] as const; const stringFilterOps = [ ...filterOps, @@ -31,7 +31,7 @@ const scalarListOps = [ 'isEmpty', 'equals', ] as const; -const JsonFilterOps = ['equals', 'in', 'notIn', 'not', 'is', 'isNot'] as const; +const JsonFilterOps = ['equals', 'in', 'notIn', 'not', 'is'] as const; const EnumFilterOps = ['equals', 'not'] as const; @Injectable() @@ -564,6 +564,13 @@ export class PrismaCrudGenerator { if (sortableTypes.includes(type as never)) { ops.push(...sortableFilterProps); } + if (type === 'Json') { + ops.push(...JsonFilterOps); + } + // type enum + if (type === 'Enum') { + ops.push(...EnumFilterOps); + } return this.builder.prismaFilter(type, { ops,