jaydenseric / graphql-multipart-request-spec

A spec for GraphQL multipart form requests (file uploads).
994 stars 54 forks source link

File downloads via GraphQL #13

Closed FluorescentHallucinogen closed 6 years ago

FluorescentHallucinogen commented 6 years ago

Everything is clear about file uploads via GraphQL using mutations. But what about file downloads via GraphQL using queries?

jaydenseric commented 6 years ago

Current practice for file downloads is for queries to resolve URL strings for the client to be able to access the files as needed. You could setup an endpoint to serve the files from wherever they are hosted (AWS S3, DigitalOcean Spaces, etc.), or even better, use a service such as imgix.

An inferior alternative is to base64 encode the files so they can be queried as a string.

There might be something else I'm not imaginative enough to realize, but I don't think ideas such as sending multipart responses to the client will be viable. If someone else has a better imagination and can think of something viable, please share!

chrisregnier commented 4 years ago

Glad I looked through the closed issues to find this, cause I was just about to ask the same thing, however I'm not entirely sure whether my suggestion merits a complete new spec doc or if it makes sense to tie it in with uploads.

Anyways I was thinking that you could just add another var named 'selector' that defines a single json path into the result (although I could see an http header working as well). Then, since graphql apis would normally use Accept: application/json, you can look for Accept: application/octet-stream to know if you should be taking the result and using the selector to pull out the result and then return it as a binary file.