We’re working on adding support for uploading (small) files to our Redwood app. We are trying to use GraphQL Yoga’s built-in support for multipart form uploads. We are running Redwood on a server, so supporting serverless functions is not a requirement.
We found a couple of barriers to using Yoga’s multipart uploads. The first is that by default, it looks like Redwood passes all request information to the GraphQL server in a simulated AWS Lambda Event, which relies on being able to parse the whole request body and feed it in as a string or Buffer. To get around this limitation, we enabled the experimental server file, so we are using the Fastify version of the Yoga server.
The second barrier to using multipart uploads seems to be Redwood’s use of the Fastify raw body plugin. This plugin simulates Express’s rawBody request field by reading the request body. Unfortunately, reading the body means the formData of the multipart form request becomes unavailable (the body can only be consumed once). To test this theory, we commented out the registration of the rawBody plugin and GraphQL uploads started working.
My question in this post is whether this direction of using a server with multipart uploads seems reasonable, and how we might disable the raw body plugin to support uploads for our case. Is the raw body of the request integral for other functionality in Redwood? Supporting multipart form uploads is one of the main reasons we would run Redwood on a server instead of Lambdas, so we are interested in how we might get it working without breaking other functionality.
Thanks!