vic / apollo-phoenix-websocket

An Apollo networkInterface for executing GraphQL queries via Phoenix Channels
Apache License 2.0
91 stars 9 forks source link

file uploads support #21

Open G3z opened 7 years ago

G3z commented 7 years ago

Are uploads supported ? absinthe plug has support for them (types) And If you think uploads over WS are not a good idea, would it be possible to use a more traditional REST approach maybe combining APW with something like apollo-upload-client

G3z commented 7 years ago

this medium article could be helpful

vic commented 7 years ago

Hey,

Have you tried simply sending the file content perhaps Base64 encoded ? Anyways when you use APW you are not serializing forms, somehow you need to construct the mutation query object, so why not simply put there the file content. Haven't had the need to upload files via APW myself, but this is what I'd try at first. Otherwise you can certainly expose the the very same schema via websockets and REST if you feel like using apollo-upload-client.

harmon25 commented 7 years ago

I am using apollo client for API, over websocket - but doing file uploads via axios + multi-part form posts.

Depending on the file sizes you are dealing with; reading the file on the client, and encoding as a string can be slow - and will not be transparently chunked like when uploading a file via a post request as multipart form.

Apollo upload client is interesting, but would require the upload server - not ideal in a phoenix/elixir stack...

I would stick with handing uploads via post, and create a generic gql object to represent the file - and to pass around download URIs to the client.

You can directly modify your apollo cache with the response of a form post/upload - which integrates file metadata etc into apollo cache nicely, for it to live with the rest of your apollo data.

My thoughts anyway!

G3z commented 7 years ago

Thank you for your suggestion I'll try that asap. I guess that's the best solution for the present but since sending blobs over websockets is possible (stackoverflow.com) I tought we could make APW feature-complete (this could require help from absinthe team)