Error: request entity too large in graphql services of node
Asked Answered
F

3

7

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

Facsimile answered 5/1, 2017 at 13:30 Comment(2)
Try set the type. var urlencodedParser = bodyParser.urlencoded({ extended:true,limit:1024*1024*20,type:'application/x-www-form-urlencoding' })Stomatology
Thanq for your response @digit, I tried it but it nor worked for me.Facsimile
D
8

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/" 
  )
);
Desirable answered 29/9, 2018 at 11:35 Comment(0)
P
1

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.

Papain answered 5/1, 2017 at 23:56 Comment(3)
Hi, thanq for your response, am using "graphql" module, not "graphql-express" module.Facsimile
Ahh okay interesting. Often you will use both packages at the same time. The graphql package deals with the schema, types, resolvers, etc while express-graphql takes a schema created from the graphql package and exposes it to the internet via an express web server.Papain
hi, the link you provided is not found can you please update.Intwine
M
0

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

Megaron answered 20/3, 2019 at 14:15 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.