I had the same problem.
I fixed using version 15.0.2 (only that version works for me)
package.json
{
"dependencies": {
"@nestjs/apollo": "^10.1.7",
"@nestjs/axios": "1.0.0",
"@nestjs/common": "^9.3.9",
"@nestjs/config": "^2.0.0",
"@nestjs/core": "^9.3.9",
"@nestjs/graphql": "10.2.0",
"@nestjs/platform-express": "^9.3.9",
"graphql": "^16.6.0",
"graphql-upload": "15.0.2"
},
"exports": {
"./GraphQLUpload.js": "./GraphQLUpload.js",
"./graphqlUploadExpress.js": "./graphqlUploadExpress.js",
"./graphqlUploadKoa.js": "./graphqlUploadKoa.js",
"./package.json": "./package.json",
"./processRequest.js": "./processRequest.js",
"./Upload.js": "./Upload.js"
}
}
tsconfig.json
{
"compilerOptions": {
"module": "commonjs",
"declaration": true,
"removeComments": true,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"allowSyntheticDefaultImports": true,
"target": "es2017",
"sourceMap": true,
"outDir": "./dist",
"baseUrl": "./",
"incremental": true,
"allowJs": true,
"maxNodeModuleJsDepth": 10
}
}
**/resolver.js
// @ts-ignore
import Upload = require('graphql-upload/Upload.js');
// @ts-ignore
import GraphQLUpload = require('graphql-upload/GraphQLUpload.js');
...
@Mutation(() => Boolean, {
name: 'uploadImages',
description: 'Insert array photos',
})
async uploadImages(
@Args('files', { type: () => [GraphQLUpload] })
files: [Upload],
@Args('metadata')
metadata: UploadImagesMetadataArgs,
): Promise<Boolean> {
const functionPrefix = 'uploadImages';
try {
let uploadImagesArgs: Array<UploadImagesArgs> = [];
for (const file of files) {
// @ts-ignore
const { filename, mimetype, encoding, createReadStream } = await file;
const stream = createReadStream();
const chunks = [];
for await (const chunk of stream) {
chunks.push(chunk);
}
const buffer = Buffer.concat(chunks);
uploadImagesArgs.push({ buffer, filename, mimetype });
// your code with connect with services for save your images
return true;
}
} catch(error){
// your code
return false;
}
}