Friday, October 16, 2020

GraphQL Upload: Pitfalls & Tricks

1. Fileupload is a big deal for GraphQL in general. As of today `apollo-server-lambda` does not support fileupload yet. The work-around is to use some server or middleware process to achieve it.

2. GraphQL documentation for Upload is limited

3. Express/Apollo or any other server with AWS Lambda is needed for GraphQL FileStreams handling

4. AWS API Gateway needed to be configured with Binary Media Types. References:

  • https://docs.aws.amazon.com/apigateway/latest/developerguide/api-gateway-payload-encodings.html
  • https://stackoverflow.com/questions/41756190/api-gateway-post-multipart-form-data

5. Binary input is expected by all GraphQL mutations when binary media types is turned on

6. CORS can be more challenging to handle at the API Gateway level due to the single GraphQL end point

7. Limited information/support on streaming libraries viz. Busboy, Form-Data, Formidable, Multer, Multiparty. Finally decided to use FormData by properly passing mimetype,filename,encoding. Reference:

  • https://npmcompare.com/compare/busboy,form-data,formidable,multer,multiparty

8. Stream hand-over had challenges. There are libraries (mentioned in above point) that help with parsing the file and text from the incoming request and handing it over to another API. References:

  • https://stackoverflow.com/questions/52963648/how-to-pass-multipart-request-from-one-server-to-another-in-nodejs
  • https://github.com/apollographql/apollo-server/issues/1854

9. Async/Await for FileStreams seems to be misbehaving in with AWS Lambda environment causing File size becomes 0 while API responding with 200. Reference:

  • https://levelup.gitconnected.com/avoiding-the-pitfalls-of-async-node-js-functions-in-aws-lambda-941220582e7a

No comments: