jaydenseric / graphql-upload

Middleware and an Upload scalar to add support for GraphQL multipart requests (file uploads via queries and mutations) to various Node.js GraphQL servers.
https://npm.im/graphql-upload
MIT License
1.43k stars 131 forks source link

Max File Size not working for apollo-server-lambda #302

Closed yevhenii-kas-oppizi closed 2 years ago

yevhenii-kas-oppizi commented 2 years ago

I'm using apollo-server-lambda for server and uploading data, but I can not set Max File size and always get nest error CleanShot 2022-05-11 at 19 14 13 Can I resolve this problem, and how?

Here is my code:


import { ApolloServer } from "apollo-server-lambda";
import Express, { Application } from "express";
import { graphqlUploadExpress } from "graphql-upload";
import { resolvers } from "./graphql/resolvers";
import { typeDefs } from "./graphql/schema";

const server = new ApolloServer({
  typeDefs,
  resolvers,
  introspection: process.env.NODE_ENV !== "production",
});

export const handler = server.createHandler({
  expressAppFromMiddleware(middleware) {
    const app: Application = Express();
    app.use(graphqlUploadExpress({ maxFileSize: 100000000, maxFiles: 10 }));
    app.use(middleware);
    return app;
  },
  expressGetMiddlewareOptions: {
    cors: {
      origin: "*",
      credentials: true,
    },
    bodyParserConfig: { limit: "100mb" },
  },
});
jaydenseric commented 2 years ago

I can't speak for how to configure apollo-server-lambda, Nest.js, or AWS Lambda regarding request size limits and things, but you need to make sure that your server infrastructure has larger limits set that the limits set in graphql-upload, otherwise the error won't be a nice one that graphql-upload produces.