Apollo Server Express: Request entity too large
Simply add an Express body parser before your Apollo server middleware:
import { json } from 'express';app.use(json({ limit: '2mb' });app.use(apolloServer.getMiddleware({ path: '/graphql' });
If you want to get fancy, you can have a separate body size limit for authenticated vs unauthenticated requests:
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' });
Not exactly sure in which version it was added, but on 2.9.15 you can apply it in applyMiddleware function.
const apolloServer = new ApolloServer(someConfig);apolloServer.applyMiddleware({ app, cors: { origin: true, credentials: true, }, bodyParserConfig: { limit:"10mb" }});