Jason Lei 3378403954 GraphQL Mutations, Aggregations, Decimals
Merging Mutations and Aggregations. Fixed Mongoose Hook to use Decimals (2 decimal places) and Floats (20 decimal places).
2018-09-10 16:05:00 +08:00

45 lines
1.1 KiB
GraphQL

const _ = require('lodash');
module.exports = {
mutation: `
upload(refId: ID, ref: String, source: String, file: Upload!): UploadFile!
`,
resolver: {
Query: {
file: false,
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;
}
}
}
}
};