Skip to content

Instantly share code, notes, and snippets.

@kimiiz55
Created March 13, 2018 06:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kimiiz55/bb6a64e454979bbe7d2815d3d7a0b908 to your computer and use it in GitHub Desktop.
Save kimiiz55/bb6a64e454979bbe7d2815d3d7a0b908 to your computer and use it in GitHub Desktop.
const { getUserId } = require("../../utils");
const { processUpload } = require("../../modules/fileApi");
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);
return ctx.db.mutation.createSupplierProduct(
{
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 }
},
images: {
connect: { id: [...imageId] }
}
}
},
info
);
}
};
module.exports = { supplierProduct };
@raeesaa
Copy link

raeesaa commented Mar 13, 2018

connect accepts an array of objects. Doing something like below should help:

return ctx.db.mutation.createSupplierProduct(
      {
        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 }
          },
          images: {
            connect:[ { id: <image_id_1> }, {id: <image_id_2>}, ...]
          }
        }
      },
      info
    );

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment