You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This is currently infeasible using the backend in 0.1 without modifying Apollo Client code.
My original thought was to use Apollo Client middleware to modify the POST request made by the Client, but I discovered: Multer works only on multipart/form-data requests, while Apollo Client sends application/json type requests to Apollo Server.
My new line of thinking is to use a dedicated Express endpoint (e.g. /tmp/uploads) to receive files. The Client will first initiate the upload and then call the GQL mutation. The server will handle the file based on information in the mutation.
Hey. Great to see someone else trying to integrate file uploads with Apollostack. Here are some of my thoughts.
You could create a custom createNetworkInterface that uses multipart/form-data. However, I think the best way would be to integrate this directly into apollo-client and apollo-server. The guys at Apollo are open for this, but ATM I think they have more important stuff to do. But I believe that both express-graphql and relay now support file uploads, so Apollo simply cannot go without it :) Probably a post-1.0 feature.
Your approach with a dedicated Express endpoint could work. But what happens if a mutation fails? You end up with some random files in /tmp/uploads and you need to do manual garbage collection. I don't really like it, but that's just my opinion. Maybe you could propose this on the Apollo repositories to get some feedback.
Again, I think that this needs to be in the core Apollo. It will be very tricky to implement it however. For example, apollo-server has 3 integrations: Express, Koa and Hapi, and each uses a different way of handling file uploads. I already have a working implementation for Koa in my fork, but it needs to be rewritten into a bodyParser-like middleware.
As for the client, I think that it should be implemented in createNetworkInterface. Check out this tutorial. Maybe we can start working on a PR together. I'm sure the guys at Apollo will help us with that.
Write out an example using Apollo Client to attach files to a mutation.
The text was updated successfully, but these errors were encountered: