I'm trying to implement a middleware that's able to read the content of the data sent on the request as multipart/data-form and later restore it back so express-graphql and graphql-upload can understand the request.
Since I need to read the content on the middleware, I'm using multer before to have access to the properties that are being sent. But when the request continue its course, the following errors is thrown BadRequestError: Missing multipart field ‘operations’
// first middleware
import multer from 'multer';
// ...
const middleware = (req: express.Request, res: express.Response, next: express.NextFunction) => {
if (req.header('Content-Type')?.startsWith('multipart/form-data')) {
const storage = multer.memoryStorage();
return multer({ storage }).single('1')(req, res, next);
}
return next();
}
export default middleware;
The problem, is that after this middleware is triggered, graphql-upload is no longer able to understand the request
mutation uploadDocument($doc: DocumentInput!, $file: Upload!) {
uploadDocument(doc: $doc, file: $file)
}
Do you know how can I restore the data on the request