A progressive Node.js framework for building efficient and scalable server-side applications.
-
This project is about compatibility and being able to add graphql-upload to Nest.js
-
The current version of graphql-upload, 5/09/2024, is 16.0.2. which has caused compatibility problems with Nest.js, commonjs modules and .mjs files.
-If you decide to use a recent version you should use it like this in the main file of your project:
async function bootstrap() {
const app = await NestFactory.create(AppModule);
const configService = app.get(ConfigService);
// ...
const { default: graphqlUploadExpress } = await import(
'graphql-upload/graphqlUploadExpress.mjs'
);
app.use(graphqlUploadExpress({ maxFileSize: 10000000, maxFiles: 10 }));
// ...
app.useGlobalPipes(new ValidationPipe());
await app.listen(configService.get<number>('port'));
}
- Personally, I prefer to use the version 13.0.0 and "@types/graphql-upload": "8.0.12", which is the one that I have used in this project.
- You can try using the following curl:
curl localhost:3000/graphql \
-H "x-apollo-operation-name: upload_file" \
-F operations='{ "query": "mutation ($file: Upload!) { upload_file(file: $file) }", "variables": { "file": null } }' \
-F map='{ "0": ["variables.file"] }' \
-F [email protected]
- If you want to use Apollo Federation you can visit the guys from Profusion.