I am working on node based graphql project, trying to send base64 format image to server.
I am using bodyparser module and configured it as bellow.
app.use(bodyparser.text({type: 'application/graphql'}));
app.use(bodyparser.json({limit: '50mb'}));
app.use(bodyparser.urlencoded({limit: '50mb', extended: true}));
I am able to send base64 images by direct node services but when it come to graphql services, it is throwing error as:
Error: request entity too large
Fixing “413 Request Entity Too Large” Error in Express To fix the “413 Request Entity Too Large” error in an Express application, you only have to update the server initialization file. This is generally called index. js or server. js and is where you initialize the Express server.
There are several ways to resolve this issue. First, you should check with your hosting provider to see what settings they recommend. Second, you can try increasing the memory limit on your web server.
Run the server and open http://localhost:5000/graphql in the browser. Click play, and this is how the browser window will look. The server can be queried via any GraphQL API client like Postman or in the browser with GraphiQL.
For the sake of helping others who are using graphql-yoga npm package. The syntax to add bodyparser option is quite different and I took hours debugging & trying to make it work so adding the code here for reference :
const { GraphQLServer } = require("graphql-yoga");
const server = new GraphQLServer({
schema, //Your schema
context, //Your context
});
const options = {
port: 1234
bodyParserOptions: { limit: "10mb", type: "application/json" },
};
server.start(options, () =>
console.log(
"Server is running\m/"
)
);
Are you using the graphql-express
npm package?
If so then the issue is likely this line: https://github.com/graphql/express-graphql/blob/master/src/parseBody.js#L112
As you can see this sets a max size of 100kb for the request.
We ran into the same issue and fixed it by forking the repository and manually increased the max request size.
This might be a nice opportunity to contribute to the package though! It would be nice if the limit were configurable.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With