如何在单个 graphql 请求中禁用多个操作

问题描述

Graphql 支持单个请求中的多个操作。这意味着可以在单个 HTTP 请求中提交无限数量的 graphql 查询,这将导致一些安全问题。有没有办法只允许单个 graphql 请求中的单个操作?

解决方法

您可以限制查询次数,如下所示

app.use('*',(req,res,next) => {
  const query = req.query.query || req.body.query || '';
  if (query.length > 1) {
    throw new Error('Only One Query allowed');
  }
  next();
});

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...