Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

file download using graphql #511

Closed
dilipreddy221 opened this issue Dec 27, 2017 · 6 comments
Closed

file download using graphql #511

dilipreddy221 opened this issue Dec 27, 2017 · 6 comments
Labels
question Developer asks to help him deal with some problem

Comments

@dilipreddy221
Copy link

Is there a way to download file using graphql?

@kamsar
Copy link
Contributor

kamsar commented Dec 27, 2017

You'd have to encode it in some form that would be transmissible via JSON (e.g. Base64). If the file isn't part of some other structured data result, it may not be a good candidate for a GraphQL API.

Note that Base64 is significantly less efficient bandwidth-wise than binary transfer, and you won't get a browser download prompt from receiving it, though it could be possible maybe to do something with data: URLs; not sure.

@joemcbride
Copy link
Member

joemcbride commented Dec 29, 2017

Ditto what @kamsar mentioned may not be the best candidate for GraphQL. You could also perhaps return a url to the file to download and handle that url on the client as another non GQL request - or present the url to the user and let the browser do the work.

The relay project has a good example of working with posting files to a GQL server.

https://github.com/graphql-dotnet/relay/blob/master/src/GraphQL.Relay/Http/Deserializer.cs#L23
https://github.com/graphql-dotnet/relay/blob/master/src/GraphQL.Relay/Http/RequestExecutor.cs#L31

@ozyman42
Copy link

ozyman42 commented Nov 8, 2019

The fact that graphql doesn't have a good answer for file download is unfortunate. I'm in a circumstance where I'm constructing a library which needs to operate using a protocol, but the underlying data transport layer is defined by the client. Graphql seems to be a good candidate for the protocol, except for when it comes to file transfer.

If I really do want to use graphql for my use-case, then the best answer I can come up with is to send a paginated response where each item in the paginated list is a base64 encoded chunk of the file. Seems pretty damn ugly + inefficient though.

Sending a link doesn't work in my case because it assumes the client chose HTTP

@sungam3r
Copy link
Member

sungam3r commented Nov 8, 2019

The fact is that the concept of File (binary block of data) does not apply to API. GraphQL is all about API. Therefore, the issue of file transfer takes on the transport and/or application layer.

@ozyman42
Copy link

ozyman42 commented Nov 9, 2019

^ Look up API

@sungam3r
Copy link
Member

sungam3r commented Dec 8, 2019

Closed as tracked in #1326

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Developer asks to help him deal with some problem
Projects
None yet
Development

No branches or pull requests

5 participants