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

Determine fetch and FormData implementations at runtime #184

Merged
merged 2 commits into from
Mar 30, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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