mirror of
				https://github.com/strapi/strapi.git
				synced 2025-10-31 01:47:13 +00:00 
			
		
		
		
	 3378403954
			
		
	
	
		3378403954
		
	
	
	
	
		
			
			Merging Mutations and Aggregations. Fixed Mongoose Hook to use Decimals (2 decimal places) and Floats (20 decimal places).
		
			
				
	
	
		
			45 lines
		
	
	
		
			1.1 KiB
		
	
	
	
		
			GraphQL
		
	
	
	
	
	
			
		
		
	
	
			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;
 | |
|         }
 | |
|       }
 | |
|     }
 | |
|   }
 | |
| };
 |