Compatibility with graphql-upload #36
-
Hi, First, thanks for all the work you are doing for these libraries! Its not much of an issue as it is a question following my transition from express-graphql to graphql-http. Express-graphql used to work with graphql-upload but now it seems to me that the handler is blocking my POST request with an image because the Content-Type is not "application/json". Is this limitation is expected? Thanks, Expected Behaviour Actual Behaviour |
Beta Was this translation helpful? Give feedback.
Replies: 5 comments 8 replies
-
Hey there, thanks for asking! This matter has already been answered in this discussion. You can always just forward the file upload requests to |
Beta Was this translation helpful? Give feedback.
-
Understood! Thanks! |
Beta Was this translation helpful? Give feedback.
-
Same issue here. Migrated from @enisdenjo you said:
I tried graphql-upload`s processRequest() when reciving a multipart/form-data Content-Type. But then I need still something to process the graphql request. As I understand it should be possible to process a multipart/form-data Content-type with So is it possible to have |
Beta Was this translation helpful? Give feedback.
-
With import express from 'express';
import { createHandler } from 'graphql-http/lib/use/express';
import graphqlUploadExpress from 'graphql-upload/graphqlUploadExpress';
import schema from './my-schema';
const app = express();
app.all(
'/graphql',
graphqlUploadExpress({ maxFileSize: 10000000, maxFiles: 10 }),
// because the GraphQL over HTTP spec does not support multipart content-type
(req, res, next) => {
if(req.headers['content-type'].startsWith('multipart/form-data')) {
req.headers['content-type'] = 'application/json';
}
next();
},
createHandler({ schema }),
);
app.listen({ port: 4000 });
console.log('Listening to port 4000'); |
Beta Was this translation helpful? Give feedback.
-
|
Beta Was this translation helpful? Give feedback.
graphql-http
supports custom request params parsers starting from v1.20.0. See more in #100.