can someone help me? <https://gist.github.com/kimi...
# prisma-whats-new
i want connect to many with array of id
r
Added a comment on your gist
k
thank you. but <image_id> is dynamic how to solve?
r
You could do something like:
Copy code
const supplierProduct = {
  async createSupplierProduct(parent, args, ctx, info) {
    const images = await Promise.all(
      args.files.map(file => processUpload(file, ctx))
    );

    const imageId = await images.map(image => image.id);

    let data = {
    	 name: args.name,
          description: args.description,
          detail: args.detail,
          tags: [...args.tags],
          inventory: args.inventory,
          retailPrice: args.retailPrice,
          wholesalePrice: args.wholesalePrice,
          category: {
            connect: { id: args.categoryId }
          }
    }

    if(imageId && imageId.length) {
    	data.images = {
    		connect: imageId.map((id) => {id})
    	}
    }
    return ctx.db.mutation.createSupplierProduct({ data }, info);
  }
};
Or even better: const supplierProduct = { async createSupplierProduct(parent, args, ctx, info) { const images = await Promise.all( args.files.map(file => processUpload(file, ctx)) ); const imageIds = await images.map(image => {id: image.id}); let data = { name: args.name, description: args.description, detail: args.detail, tags: [...args.tags], inventory: args.inventory, retailPrice: args.retailPrice, wholesalePrice: args.wholesalePrice, category: { connect: { id: args.categoryId } } } if(imageIds && imageIds.length) { data.images = { connect: imageIds } } return ctx.db.mutation.createSupplierProduct({ data }, info); } };
k
error images":{"connect":[null,null,null]}}; Expected non-nullable
r
Check for the value of
imageIds
. Looks like it is not being built correctly. I guess you should be able to debug this
By the way why do you have await here:
const imageIds = await images.map(image => {id: image.id});
?
It won't work with await
k
i’m try debug 😭