Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error: request entity too large in graphql services of node

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

like image 348
Harsha Vardhan Avatar asked Jan 05 '17 13:01

Harsha Vardhan


People also ask

How do I fix request entity too large node?

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.

How to fix 413 request Entity Too Large error in Node JS?

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.

How do I connect to a GraphQL 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.


2 Answers

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/" 
  )
);
like image 143
Sumeet Jain Avatar answered Oct 06 '22 09:10

Sumeet Jain


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.

like image 39
mparis Avatar answered Oct 06 '22 09:10

mparis