me keep
This commit is contained in:
@@ -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,
|
||||||
|
});
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
}));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ import * as Prisma from '@prisma/client';
|
|||||||
import { SchemaBuilderToken } from '@smatch-corp/nestjs-pothos';
|
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 sortableFilterProps = ['lt', 'lte', 'gt', 'gte'] as const;
|
||||||
const stringFilterOps = [
|
const stringFilterOps = [
|
||||||
...filterOps,
|
...filterOps,
|
||||||
@@ -31,7 +31,7 @@ const scalarListOps = [
|
|||||||
'isEmpty',
|
'isEmpty',
|
||||||
'equals',
|
'equals',
|
||||||
] as const;
|
] 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;
|
const EnumFilterOps = ['equals', 'not'] as const;
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
@@ -564,6 +564,13 @@ export class PrismaCrudGenerator<Types extends SchemaTypes> {
|
|||||||
if (sortableTypes.includes(type as never)) {
|
if (sortableTypes.includes(type as never)) {
|
||||||
ops.push(...sortableFilterProps);
|
ops.push(...sortableFilterProps);
|
||||||
}
|
}
|
||||||
|
if (type === 'Json') {
|
||||||
|
ops.push(...JsonFilterOps);
|
||||||
|
}
|
||||||
|
// type enum
|
||||||
|
if (type === 'Enum') {
|
||||||
|
ops.push(...EnumFilterOps);
|
||||||
|
}
|
||||||
|
|
||||||
return this.builder.prismaFilter(type, {
|
return this.builder.prismaFilter(type, {
|
||||||
ops,
|
ops,
|
||||||
|
|||||||
Reference in New Issue
Block a user