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
Comments
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. |
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 |
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 |
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. |
^ Look up API |
Closed as tracked in #1326 |
Is there a way to download file using graphql?
The text was updated successfully, but these errors were encountered: