Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

File uploads using apollo-server-lambda #1419

Closed
taikn opened this issue Jul 25, 2018 · 28 comments · Fixed by #3926
Closed

File uploads using apollo-server-lambda #1419

taikn opened this issue Jul 25, 2018 · 28 comments · Fixed by #3926
Labels
📝 documentation Focuses on changes to the documentation (docs)

Comments

@taikn
Copy link

taikn commented Jul 25, 2018

Hi,
Could not find any mention, whether apollo-server-lambda supports the GraphQL multipart request specification for uploading files as mutation arguments (like apollo-server does)

@ghost ghost added the 📝 documentation Focuses on changes to the documentation (docs) label Jul 25, 2018
@unicodeveloper
Copy link
Contributor

Hello @taikn apollo-server-lambda supports uploading files as mutation arguments like apollo-server does!

@taikn
Copy link
Author

taikn commented Jul 26, 2018

Hmmm, I am getting following error, when trying to upload a file using apollo-server-lambda, while uploading a file using apollo-server with same config, works without problems.

SyntaxError: Unexpected number in JSON at position 1
at JSON.parse (<anonymous>)
at graphqlHandler (/var/task/node_modules/apollo-server-lambda/dist/lambdaApollo.js:24:24)
at /var/task/node_modules/apollo-server-lambda/dist/ApolloServer.js:87:85

@tomyitav
Copy link

@taikn +1, getting the same error on simple graphql query execution:
erroroncloudswatch

@AlpacaGoesCrazy
Copy link

AlpacaGoesCrazy commented Aug 27, 2018

I think that this error is due to apollo-server-lambda tries to parse event.body as JSON while apollo-upload-client sends uploading request with multipart/form-data content type
Here it is: https://github.com/apollographql/apollo-server/blob/master/packages/apollo-server-lambda/src/lambdaApollo.ts#L46
@unicodeveloper I guess it should parse such requests with something else to actually support uploading files?

@sunny-knowre
Copy link

any updates on this? having the same issue as well.

@javiermanzano
Copy link

Having the same issue here. Any solutions?

@henrinormak
Copy link

henrinormak commented Sep 23, 2018

...apollo-server-lambda supports uploading files as mutation arguments like apollo-server does!

@unicodeveloper - I don't believe that's true, going over the source code of apollo-server-lambda, there are no references to apollo-server-upload, compare that to the koa and express variants, which both explicitly call processRequest from apollo-upload-server as middleware that runs before the actual query is run. Could you explain how the file upload is supposed to work in apollo-server-lambda?

@stanleycyang
Copy link

Seeing this error as well.

@yornaath
Copy link

yornaath commented Oct 8, 2018

Im also getting this error using apollo-server-lambda

@derdrdirk
Copy link

Anybody able to fix this?

@craigcartmell
Copy link

I'd be keen for an update on this too. Or an alternative solution?

This looks like it could potentially be useful: https://github.com/myshenin/aws-lambda-multipart-parser#readme

@jakebenn
Copy link

+1

@NHebrard
Copy link

Same need here

@eliliam
Copy link

eliliam commented May 25, 2019

This still is an issue, does anyone have any updates on this?

@nemmarramos
Copy link

Any updates?

@jbaxleyiii jbaxleyiii added the 🚧👷‍♀️👷‍♂️🚧 in triage Issue currently being triaged label Jul 8, 2019
@jbaxleyiii
Copy link
Contributor

Thanks very much for reporting this! We think this is a great idea, and would definitely review a PR. If you (or anyone else) is interested in working on this, that would be great - thanks!

@abernix abernix removed 🚧👷‍♀️👷‍♂️🚧 in triage Issue currently being triaged labels Jul 9, 2019
@mrfoster
Copy link

mrfoster commented Aug 2, 2019

@jbaxleyiii Why was this issue closed? There is an open pull request here: #1739

@totteire
Copy link

totteire commented Oct 29, 2019

@jbaxleyiii Still waiting for the file upload to work in apollo-server-lambda ...
Any update ? I get the JSON.parse error.
Meanwhile I use another lambda without apollo to handle my file uploads :( but it makes me so sad ;(

abernix added a commit that referenced this issue Apr 10, 2020
Aim to provide file-upload parity support — as already supported within
the other Apollo Server integration packages — via the third-party
`graphql-upload` package.

Co-authored-by: charleswong28 <[email protected]>
Co-authored-by: Steve Babigian <[email protected]>
Co-authored-by: Jesse Rosenberger <[email protected]>
Closes: #1419
Closes: #1703
Supersedes: #1739
...and therefore...
Closes: #1739
Supersedes: #3676
...and therefore...
Closes: #3676
@dcai-icfi
Copy link

This works! But there seems to be the limit of file size. I got this error when I tried to upload a large file like ~30M:

error: "Request Entity Too Large"
message: "Payload content length greater than maximum allowed: 10485760"
statusCode: 413

It's similar to this issue: #3354
But in that case, it uses apollo-server-express. I cannot do the suggestion that @abernix provided:

serverApollo.applyMiddleware({
  app,
  route: {
    payload: {
      maxBytes: 52428800,
    },
  },
});

I also tried:

const options = {
  uploadsConfig: {
    maxFieldSize: 52428800, // bytes = 50MB
    maxFileSize: 52428800,
    maxFiles: 10
  }
};
ApolloServer.createHandler(options);

But it does not take uploadsConfig. Any ideas?

Thanks!

@Santhosh222
Copy link

This is not working. I got a new error in apollo server lambda but works fine in apollo server.
Exception -----------------------------------------------

[
[Error: Missing Content-Type] {
locations: undefined,
path: undefined,
extensions: { code: 'INTERNAL_SERVER_ERROR' }
}
]

@mathix420
Copy link
Contributor

@dcai-icfi it seems you are facing to a hard limit of AWS Lambda (Invocation payload | 6 MB) https://docs.aws.amazon.com/lambda/latest/dg/gettingstarted-limits.html#w603aac11c66c15

@GolivetsAndreu
Copy link

@Santhosh222 Did you resolve your solution?

@digitinfinitum
Copy link

This is not working. I got a new error in apollo server lambda but works fine in apollo server.
Exception -----------------------------------------------

[
[Error: Missing Content-Type] {
locations: undefined,
path: undefined,
extensions: { code: 'INTERNAL_SERVER_ERROR' }
}
]

I'm getting same issue

@GolivetsAndreu
Copy link

@it-crafter see #5093, I think it can help you

@donalatorre
Copy link

donalatorre commented Aug 16, 2021

I also faced this issue, and found no decent solution to implementing file uploads in apollo-server-lambda.
So I decided to abandon apollo-server-lambda completely, since it doesn't seem to be getting much attention or maintenance.

I found that what I needed was totally achievable with apollo-server-express, graphql-upload, and serverless-http.

src/index.ts

import {
  ApolloServer,
  gql
} from "apollo-server-express";
import express from "express";
import {
  graphqlUploadExpress, // The Express middleware.
  GraphQLUpload, // The GraphQL "Upload" Scalar
} from "graphql-upload";
import serverless from "serverless-http";

const typeDefs = gql`
  scalar Upload
  ... your schema ...
`

const resolvers = {
  Upload: GraphQLUpload as any,
  //... your resolvers ...
}

const server = new ApolloServer({
  typeDefs,
  resolvers,
  introspection: true,
  uploads: false, // Cancel the default apollo upload option
});

const app = express();
app.use(graphqlUploadExpress()); // Apply the express upload middleware
server.applyMiddleware({ app });

exports.handler = serverless(app);

@steve-keep
Copy link

steve-keep commented Aug 23, 2021

This worked for me in the end:

exports.handler = server.createHandler({
	expressGetMiddlewareOptions: { bodyParserConfig: { limit: '50mb' } },
});

@amiklosi
Copy link

Thanks @skeep-exogee , that was a day saver!

@mateo2181
Copy link

mateo2181 commented Nov 16, 2021

@skeep-exogee can you share the configuration you use? I'm using apollo-server-lambda with graphqlUploadExpress but it is not working. I'm testing it from Firecamp to send the file.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Apr 20, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
📝 documentation Focuses on changes to the documentation (docs)
Projects
None yet