Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
productIds: idArg({ required: true, list: true }),
collectionId: idArg({ required: true }),
},
resolve: async (_, args, ctx) => {
const collection = await ctx.prisma.updateCollection({
where: { id: args.collectionId },
data: { products: { connect: args.productIds.map(id => ({ id })) } },
})
return collection
},
})
t.field('removeProductsFromCollection', 'Collection', {
args: {
productIds: idArg({ required: true, list: true }),
collectionId: idArg({ required: true }),
},
resolve: async (_, args, ctx) => {
const collection = await ctx.prisma.updateCollection({
where: { id: args.collectionId },
data: { products: { disconnect: args.productIds.map(id => ({ id })) } },
})
return collection
},
})
t.field('createProduct', 'Product', {
args: {
data: arg('CreateProductInput', { required: true }),
},
export const Mutation = prismaObjectType('Mutation', t => {
t.field('addProductsToCollection', 'Collection', {
args: {
productIds: idArg({ required: true, list: true }),
collectionId: idArg({ required: true }),
},
resolve: async (_, args, ctx) => {
const collection = await ctx.prisma.updateCollection({
where: { id: args.collectionId },
data: { products: { connect: args.productIds.map(id => ({ id })) } },
})
return collection
},
})
t.field('removeProductsFromCollection', 'Collection', {
args: {
productIds: idArg({ required: true, list: true }),
collectionId: idArg({ required: true }),
},
export const Query = prismaObjectType('Query', t => {
t.prismaFields({ pick: ['products', 'options', 'brands'] })
t.field('collection', 'Collection', {
args: {
collectionId: idArg({ required: true }),
},
resolve: (root, args, ctx) => {
return ctx.prisma.collection({ id: args.collectionId })
},
})
})