keystonejs-contrib / k6-contrib

Keyston-6 contrib
MIT License
35 stars 18 forks source link

seed data to the azureStorageImage field #36

Open relusion opened 2 years ago

relusion commented 2 years ago

Hi,

I am trying to upload a file to a list with a field of type azureStorageImage. I've tried already many different things, but cannot make it to work. Maybe someone can point me where I am doing something obviously wrong, what else I could try:

Error I am getting: GraphQLError: Variable "$data" got invalid value { resolve: [function], reject: [function], promise: {}, file: { createReadStream: [function createReadStream], filename: "blabla.png", mimetype: "image/png", encoding: "utf-8" } } at "data.logo.upload"; Upload value invalid.

import { azureStorageImage } from "@k6-contrib/fields-azure";

export const TestList = list(withLogging({
    fields: {              
        name: text({ validation: { isRequired: true }, isIndexed: 'unique' }),             
        logo: azureStorageImage({
            azureStorageConfig: PublicAzureStorageConfig
        }),
    }
}));

and the code I am using to create new items and upload images.

await context.query.TestList.createOne({
    data: {
        name: 'name value',
        logo:  {
          upload: prepareToUpload(".... here is a path to a local file")                        
        }
    },
    query: 'id',
});

import Upload from 'graphql-upload/public/Upload.js';

export const prepareToUpload = (infilePath: string) => {
  let filePath = `${__dirname}/test-files/${infilePath}`;

  const filename = path.basename(filePath)

  const createReadStream = () => fs.createReadStream(filePath)
  // @ts-ignore
  const mimetype = mime.getType(filePath)
  const encoding = 'utf-8'

  const image = {
    createReadStream,
    filename,
    mimetype,
    encoding,
  }

  const upload = new Upload()
  // @ts-ignore
  //upload.resolve(image);
  upload.resolve(image);

  return upload
}