Error: request entity too large in graphql services of node

10.2k views Asked by At

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

3

There are 3 answers

3
mparis On

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.

0
Sumeet Jain On

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/" 
  )
);
0
quizzilie On

For me, I specified the uploads and it worked:

const options = {
  uploads: {
    maxFieldSize: 1000000000,
    maxFileSize: 1000000000
  }
}

bodyParser only works with req.body and in your case you're handling multipart form