-
Notifications
You must be signed in to change notification settings - Fork 32
Enable file uploads via mutation or query input variables. #8
Conversation
I dropped setting the Note that according to the fetch spec, setting the |
fetchOptions.body = new FormData(); | ||
fetchOptions.body.append('operations', JSON.stringify(request)); | ||
files.forEach(({ path, file }) => fetchOptions.body.append(path, file)); | ||
} else { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing fetchOptions.headers['Content-Type'] = 'multipart/form-data';
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, as per the fetch
spec it gets set automatically when the body is FormData
.
@stubailo @evanshauser @jbaxleyiii very excited to hear your thoughts and see this progress. It's taken the week to get this PR together so I have to get back onto project work now. It would be great if whoever is most familiar with the tests here could update them for this functionality. If everyone is happy with the approach I can help out updating the docs, although you should be able to pinch paragraphs from Once |
@jaydenseric will it be possible to get the upload progress so progress bar (or percentage) can be shown on client? |
@vladshcherbin unfortunately no, as Keep in mind that the actual upload is sometimes just part of the wait for a mutation response – the server takes time to process the request and that is not easy to assign progress. Then the response download happens. So the UI might be loading progress, then a spinner, then perhaps a brief progress again. |
@jaydenseric maybe it's a good idea to consider XHR from the beginning because while for a regular form the loading percentage is not that relevant, for a file upload it really is. If implemented, it gives better UX and is really useful when you upload multiple files and want to show percentage for each of them or your mutation just uploads file on dropzone file drop. |
@vladshcherbin this PR (and A new Apollo API for tracking query progress would be handy and could be implemented later as an enhancement to benefit all large queries; not just ones containing files. This wouldn't show upload progress for individual files – it would be for the GraphQL request as a whole including all files within variables and query JSON. If you need to track uploads separately you could make seperate mutation requests. This hypothetical progress API has been suggested before and might never happen. Having uploads without progress is still very useful to a lot of people now, evidenced by the exponential growth of This PR will not be the only way to upload files in an app, people can still use XHR and a traditional REST endpoint. |
@jaydenseric while the whole apollo query tracking may be useful, I don't understand why we need to wait for it and for file upload progress when we can have it now while adding file upload functionality. People will be still using Anyway, I respect all you work and decisions, this was just the feature I'd love to have. Thank you! |
I would like the feature too. It will be an effort across several repos. The network interfaces would need to be re-written to XHR, then we need to establish a way for them to report query progress to Apollo Client. Batching could complicate things as progress would be shared. React Apollo would then need an API for progress callbacks and props when decorating components. Changes would need to be made to each moving part with compatibility in mind so nothing breaks. |
@jaydenseric Thank you so much for contributing and adding to the community! Very sorry for the lack of response. We were pushing hard for a prerelease of apollo-link We've been discussing The reason to make the The PR will also include batching support, so the signature of If you have any early concerns, please let me know. Thank you again for taking charge of file upload in |
@jaydenseric #10 is merged, so batching and |
@evanshauser thanks, working on it now. I might Slack you about using Lerna to locally dev and test a new sub package. |
Closing in favor of #14. |
Files can now be uploaded via mutation or query input variables, implementing the
apollo-upload-client
multipart request method. Users must setupapollo-upload-server
to use this feature until support is added tographql-server
. An unmodified API server will continue to work fine if users don't attempt uploads.You can try it out by cloning the apollo-upload-examples
fetch
branch. Usenpm link
to try it out with this PR.Fixes #6.
TODO: