This commit is contained in:
2024-10-14 16:06:21 +07:00
parent 12386d0255
commit 6c04f52ddd
2 changed files with 42 additions and 2 deletions

View File

@@ -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,
});
},
}),
}));
}
}