45 lines
1.1 KiB
GraphQL
Raw Normal View History

const _ = require('lodash');
2018-04-10 12:56:13 +02:00
module.exports = {
mutation: `
upload(refId: ID, ref: String, source: String, file: Upload!): UploadFile!
`,
2018-04-10 12:56:13 +02:00
resolver: {
Query: {
file: false,
2018-04-10 12:56:13 +02:00
files: {
resolver: 'Upload.find'
}
},
Mutation: {
createFile: false,
updateFile: false,
deleteFile: false,
upload: {
description: 'Upload one or many files',
resolver: async (obj, { file, ...fields}, { context }) => {
// Construct context to fit with koa-parser guidelines
// and avoid to update our business logic too much.
context.request.body = {
files: {
files: await file
},
fields
};
// Call controller action.
await strapi.plugins.upload.controllers.upload.upload(context);
// Handle case when the user is uploading only one file.
if (_.isArray(context.body) && context.body.length === 1) {
return context.body[0];
}
// Return response.
return context.body;
}
}
2018-04-10 12:56:13 +02:00
}
}
};