Skip to content

Commit

Permalink
Merge pull request #184 from yaacovCR/no-unnecessary-polyfills
Browse files Browse the repository at this point in the history
Determine fetch and FormData implementations at runtime.
  • Loading branch information
jaydenseric committed Mar 30, 2020
2 parents e075e9c + 10c90c1 commit a0d3b91
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
2 changes: 1 addition & 1 deletion changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

### Minor

- Support uploading files from a server environment, fixing [#172](https://github.com/jaydenseric/apollo-upload-client/issues/172) via [#179](https://github.com/jaydenseric/apollo-upload-client/pull/179).
- Support uploading files from a server environment, fixing [#172](https://github.com/jaydenseric/apollo-upload-client/issues/172) via [#179](https://github.com/jaydenseric/apollo-upload-client/pull/179) and [#184](https://github.com/jaydenseric/apollo-upload-client/pull/184).
- Added `createUploadLink` options:
- `isExtractableFile`
- `FormData`
Expand Down
12 changes: 8 additions & 4 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -173,9 +173,9 @@ exports.formDataAppendFile = formDataAppendFile
exports.createUploadLink = ({
uri: fetchUri = '/graphql',
isExtractableFile: customIsExtractableFile = isExtractableFile,
FormData: CustomFormData = FormData,
FormData: CustomFormData,
formDataAppendFile: customFormDataAppendFile = formDataAppendFile,
fetch: customFetch = fetch,
fetch: customFetch,
fetchOptions,
credentials,
headers,
Expand Down Expand Up @@ -230,7 +230,9 @@ exports.createUploadLink = ({
// GraphQL multipart request spec:
// https://github.com/jaydenseric/graphql-multipart-request-spec

const form = new CustomFormData()
const RuntimeFormData = CustomFormData || FormData

const form = new RuntimeFormData()

form.append('operations', payload)

Expand Down Expand Up @@ -262,7 +264,9 @@ exports.createUploadLink = ({
}
}

customFetch(uri, options)
const runtimeFetch = customFetch || fetch

runtimeFetch(uri, options)
.then(response => {
// Forward the response on the context.
operation.setContext({ response })
Expand Down

0 comments on commit a0d3b91

Please sign in to comment.