Correctly infer and set content-type #37
Closed
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Firstly, thanks for your work in getting file uploading working with Apollo.
I was testing v6.0.0-beta1 of apollo-upload-client and ran into a mysterious bug.
Context:
We have a component which will first fetch a list of items (via GraphQL), then render them in the UI. The user can then click on an item and attach a document.
When I tried to upload documents, the request would barf on the server (I use a custom gem to make this all work in a Rails server context). It was because the
content-type
header in the request wasapplication/json
.After some (a lot because I'm new to npm debugging) debugging, I confirmed that this line(51):
was altering the original headers object which I gave when I called
createUploadLink(...)
. This is obvious in hindsight since objects are passed by reference in Javscript.I see two possible solutions:
fetchOptions
every requestI like (2) because it's easier.
I'm putting up this PR in case you want to go this route. I realize you may go another route to address this problem, but in the meantime I will just be using this for my project.
Testing
The
npm build
script fails in my environment, so I just tested by copying the index.mjs file directly over and verifying that uploading a file worked in the aforementioned scenario/context. Let me know if you'd like me to test in a different way.