简体   繁体   English

错误:请求实体在节点的graphql服务中太大

[英]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. 我正在基于节点的graphql项目上工作,尝试将base64格式的图像发送到服务器。

I am using bodyparser module and configured it as bellow. 我正在使用bodyparser模块,并将其配置为波纹管。

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: 我能够通过直接节点服务发送base64图像,但是当涉及到graphql服务时,它会抛出如下错误:

Error: request entity too large 错误:请求实体太大

For the sake of helping others who are using graphql-yoga npm package. 为了帮助其他使用graphql-yoga npm软件包的人。 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 : 添加bodyparser选项的语法非常不同,我花了数小时进行调试并尝试使其工作,因此在此处添加代码以供参考:

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? 您是否正在使用graphql-express npm软件包?

If so then the issue is likely this line: https://github.com/graphql/express-graphql/blob/master/src/parseBody.js#L112 如果是这样,那么问题可能出在以下这一行: 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. 如您所见,这为请求设置了最大100kb的大小。

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. 如果限制是可配置的,那就太好了。

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 bodyParser仅与req.body一起req.body ,在您的情况下,您正在处理多部分表单

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM