apollo-server-integrations / apollo-server-integration-aws-lambda

An integration to use AWS Lambda as a hosting service with Apollo Server
MIT License
46 stars 9 forks source link

File upload support #86

Closed danieljarrett74 closed 1 year ago

danieljarrett74 commented 1 year ago

Just wondering if there's any support for file uploads for Lambda. there doesn't appear to be any documentation on this.

3alqassab commented 1 year ago

Got the same question...

BlenderDude commented 1 year ago

Currently, this library only supports JSON payloads, which means the standard file upload implementation won't work.

File uploads via GraphQL are generally discouraged. The preferred pattern is to utilize an out-of-band upload system like an S3 pre-signed upload link. You can read about that here. Lambda also has a relatively small upload limit, 6MB in base64 (so less in practice), which means even some photos will have trouble uploading.

The functionality of GraphQL upload's graphqlUploadExpress function could be reproduced as a middleware to this library, but I recommend using the solution outlined above with S3. The other option is to create a custom Buffer scalar that accepts a base64 payload from the client and transforms it to a NodeJS buffer on the server. This would allow for small uploads to work without graphql-upload and without stepping out of the application/json content type.

BlenderDude commented 1 year ago

Closing as won't fix unless there is a good reason to implement it otherwise. Given the general advice to not do upload handling in GraphQL, any implementation right now should utilize a middleware to catch and handle such requests.