Apollo Server Express:请求实体太大

Apollo Server Express:请求实体太大,express,graphql,apollo,apollo-server,Express,Graphql,Apollo,Apollo Server,我需要在GraphQL中发布一个大负载。如何增加阿波罗服务器的机身尺寸限制 我正在使用apollo server express的2.9.3版 我的代码(简化): 只需在Apollo服务器中间件之前添加一个Express body解析器: import { json } from 'express'; app.use(json({ limit: '2mb' }); app.use(apolloServer.getMiddleware({ path: '/graphql' }); 如果您想了

我需要在GraphQL中发布一个大负载。如何增加阿波罗服务器的机身尺寸限制

我正在使用apollo server express的
2.9.3版

我的代码(简化):


只需在Apollo服务器中间件之前添加一个Express body解析器:

import { json } from 'express';

app.use(json({ limit: '2mb' });
app.use(apolloServer.getMiddleware({ path: '/graphql' });

如果您想了解更多,可以对已验证和未验证的请求设置单独的正文大小限制:

const jsonParsers = [
  json({ limit: '16kb' }),
  json({ limit: '2mb' }),
];

function parseJsonSmart(req: Request, res: Response, next: NextFunction) {
  // How exactly you do auth depends on your app
  const isAuthenticated = req.context.isAuthenticated();
  return jsonParsers[isAuthenticated ? 1 : 0](req, res, next);
}

app.use(parseJsonSmart);
app.use(apolloServer.getMiddleware({ path: '/graphql' });

只需在Apollo服务器中间件之前添加一个Express body解析器:

import { json } from 'express';

app.use(json({ limit: '2mb' });
app.use(apolloServer.getMiddleware({ path: '/graphql' });

如果您想了解更多,可以对已验证和未验证的请求设置单独的正文大小限制:

const jsonParsers = [
  json({ limit: '16kb' }),
  json({ limit: '2mb' }),
];

function parseJsonSmart(req: Request, res: Response, next: NextFunction) {
  // How exactly you do auth depends on your app
  const isAuthenticated = req.context.isAuthenticated();
  return jsonParsers[isAuthenticated ? 1 : 0](req, res, next);
}

app.use(parseJsonSmart);
app.use(apolloServer.getMiddleware({ path: '/graphql' });

不确定它是在哪个版本添加的,但在2.9.15中,您可以在applyMiddleware函数中应用它

const apolloServer = new ApolloServer(someConfig);
apolloServer.applyMiddleware({
  app,
  cors: {
    origin: true,
    credentials: true,
  },
  bodyParserConfig: {
    limit:"10mb"
  }
});

不确定它是在哪个版本添加的,但在2.9.15中,您可以在applyMiddleware函数中应用它

const apolloServer = new ApolloServer(someConfig);
apolloServer.applyMiddleware({
  app,
  cors: {
    origin: true,
    credentials: true,
  },
  bodyParserConfig: {
    limit:"10mb"
  }
});