From f318ef8c211e543f2d4917a03e2dd2f74ff328b0 Mon Sep 17 00:00:00 2001 From: Hoang Vo <40987398+hoangvvo@users.noreply.github.com> Date: Sat, 1 Feb 2020 15:37:51 -0500 Subject: [PATCH 01/27] Use apollo-client v3 --- package.json | 7 ++++--- src/index.js | 5 +++-- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/package.json b/package.json index 576de4e..ad1a2fe 100644 --- a/package.json +++ b/package.json @@ -33,13 +33,15 @@ "node": ">=8.10" }, "browserslist": "Node >= 8.10, > 0.5%, not OperaMini all, not dead", + "peerDependencies": { + "@apollo/client": "*" + }, "dependencies": { "@babel/runtime": "^7.5.4", - "apollo-link": "^1.2.12", - "apollo-link-http-common": "^0.2.14", "extract-files": "^5.0.1" }, "devDependencies": { + "@apollo/client": "^3.0.0-beta.31", "@babel/cli": "^7.5.0", "@babel/core": "^7.5.4", "@babel/plugin-transform-runtime": "^7.5.0", @@ -54,7 +56,6 @@ "eslint-plugin-jsdoc": "^18.1.5", "eslint-plugin-node": "^10.0.0", "eslint-plugin-prettier": "^3.1.0", - "graphql": "^14.4.2", "husky": "^3.0.0", "jsdoc-md": "^4.0.1", "lint-staged": "^9.1.0", diff --git a/src/index.js b/src/index.js index 25c28d8..dd99611 100644 --- a/src/index.js +++ b/src/index.js @@ -1,12 +1,13 @@ -const { ApolloLink, Observable } = require('apollo-link') const { + ApolloLink, + Observable, selectURI, selectHttpOptionsAndBody, fallbackHttpConfig, serializeFetchParameter, createSignalIfSupported, parseAndCheckHttpResponse -} = require('apollo-link-http-common') +} = require('@apollo/client') const { extractFiles, ReactNativeFile } = require('extract-files') /** From 7b4e4b3c605e977c5a9ba7d77b965566bf3a87a1 Mon Sep 17 00:00:00 2001 From: Hoang Vo <40987398+hoangvvo@users.noreply.github.com> Date: Sat, 1 Feb 2020 15:48:55 -0500 Subject: [PATCH 02/27] Support GET requests --- src/index.js | 28 ++++++++++++++++++++++++---- 1 file changed, 24 insertions(+), 4 deletions(-) diff --git a/src/index.js b/src/index.js index dd99611..3473f1c 100644 --- a/src/index.js +++ b/src/index.js @@ -6,8 +6,12 @@ const { fallbackHttpConfig, serializeFetchParameter, createSignalIfSupported, - parseAndCheckHttpResponse + parseAndCheckHttpResponse, + fromError } = require('@apollo/client') +const { + rewriteURIForGET +} = require('@apollo/client/link/http/rewriteURIForGET') const { extractFiles, ReactNativeFile } = require('extract-files') /** @@ -99,7 +103,8 @@ exports.createUploadLink = ({ fetchOptions, credentials, headers, - includeExtensions + includeExtensions, + useGETForQueries } = {}) => { const linkConfig = { http: { includeExtensions }, @@ -109,7 +114,7 @@ exports.createUploadLink = ({ } return new ApolloLink(operation => { - const uri = selectURI(operation, fetchUri) + let uri = selectURI(operation, fetchUri) const context = operation.getContext() // Apollo Engine client awareness: @@ -167,7 +172,22 @@ exports.createUploadLink = ({ }) options.body = form - } else options.body = payload + } else { + // If requested, set method to GET if there are no mutations. + const definitionIsMutation = d => + d.kind === 'OperationDefinition' && d.operation === 'mutation' + if ( + useGETForQueries && + !operation.query.definitions.some(definitionIsMutation) + ) + options.method = 'GET' + + if (options.method === 'GET') { + const { newURI, parseError } = rewriteURIForGET(uri, body) + if (parseError) return fromError(parseError) + uri = newURI + } else options.body = payload + } return new Observable(observer => { // If no abort controller signal was provided in fetch options, and the From 61d4007b70bb70af08583d5e85cac3b8e7c6778a Mon Sep 17 00:00:00 2001 From: Hoang <40987398+hoangvvo@users.noreply.github.com> Date: Sat, 1 Feb 2020 16:36:09 -0500 Subject: [PATCH 03/27] Fix abort controller --- src/index.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/index.js b/src/index.js index 3473f1c..bd3fd16 100644 --- a/src/index.js +++ b/src/index.js @@ -195,10 +195,10 @@ exports.createUploadLink = ({ // default abort controller. let abortController if (!options.signal) { - const { controller } = createSignalIfSupported() + const { controller, signal } = createSignalIfSupported() if (controller) { abortController = controller - options.signal = abortController.signal + if (controller) options.signal = signal } } From 26206e7af9fe72a07d2dcfd01e5d70f0d2cf1794 Mon Sep 17 00:00:00 2001 From: Hoang <40987398+hoangvvo@users.noreply.github.com> Date: Sat, 1 Feb 2020 21:32:30 -0500 Subject: [PATCH 04/27] remove dup --- src/index.js | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/index.js b/src/index.js index bd3fd16..80e41ff 100644 --- a/src/index.js +++ b/src/index.js @@ -196,10 +196,8 @@ exports.createUploadLink = ({ let abortController if (!options.signal) { const { controller, signal } = createSignalIfSupported() - if (controller) { - abortController = controller - if (controller) options.signal = signal - } + abortController = controller + if (controller) options.signal = signal } linkFetch(uri, options) From 5a513c2cf63fa0b2d20ce62ad3b42e0c27ea8a80 Mon Sep 17 00:00:00 2001 From: Hoang <40987398+hoangvvo@users.noreply.github.com> Date: Sun, 2 Feb 2020 19:31:49 -0500 Subject: [PATCH 05/27] Update package.json Co-Authored-By: Jayden Seric --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index ad1a2fe..1fe6a83 100644 --- a/package.json +++ b/package.json @@ -34,7 +34,7 @@ }, "browserslist": "Node >= 8.10, > 0.5%, not OperaMini all, not dead", "peerDependencies": { - "@apollo/client": "*" + "@apollo/client": "^3.0.0" }, "dependencies": { "@babel/runtime": "^7.5.4", From e929208371d328c80ad2cc0996e3db6a8fca49c5 Mon Sep 17 00:00:00 2001 From: Hoang Vo <40987398+hoangvvo@users.noreply.github.com> Date: Sun, 2 Feb 2020 19:33:41 -0500 Subject: [PATCH 06/27] revert --- src/index.js | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/index.js b/src/index.js index 80e41ff..3473f1c 100644 --- a/src/index.js +++ b/src/index.js @@ -195,9 +195,11 @@ exports.createUploadLink = ({ // default abort controller. let abortController if (!options.signal) { - const { controller, signal } = createSignalIfSupported() - abortController = controller - if (controller) options.signal = signal + const { controller } = createSignalIfSupported() + if (controller) { + abortController = controller + options.signal = abortController.signal + } } linkFetch(uri, options) From 39256a01917cf09af8f8815ee86eb8fa98fcae8d Mon Sep 17 00:00:00 2001 From: Hoang Vo <40987398+hoangvvo@users.noreply.github.com> Date: Sun, 2 Feb 2020 19:39:44 -0500 Subject: [PATCH 07/27] Move fn into .some --- src/index.js | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/index.js b/src/index.js index 3473f1c..b40a273 100644 --- a/src/index.js +++ b/src/index.js @@ -174,11 +174,13 @@ exports.createUploadLink = ({ options.body = form } else { // If requested, set method to GET if there are no mutations. - const definitionIsMutation = d => - d.kind === 'OperationDefinition' && d.operation === 'mutation' if ( useGETForQueries && - !operation.query.definitions.some(definitionIsMutation) + !operation.query.definitions.some( + definition => + definition.kind === 'OperationDefinition' && + definition.operation === 'mutation' + ) ) options.method = 'GET' From 5eb20342790ae06baef23e8c7fc15ebab18d5ab4 Mon Sep 17 00:00:00 2001 From: Hoang Vo <40987398+hoangvvo@users.noreply.github.com> Date: Mon, 27 Apr 2020 09:24:33 -0400 Subject: [PATCH 08/27] typo --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 856a240..cd3d041 100644 --- a/package.json +++ b/package.json @@ -39,7 +39,7 @@ }, "peerDependencies: { "@apollo/client": "^3.0.0-beta.31" - } + }, "devDependencies": { "@babel/cli": "^7.8.4", "@babel/core": "^7.9.0", From a4cf53423ff803215e13b7ab8d7c8e9d6e872970 Mon Sep 17 00:00:00 2001 From: Hoang Vo <40987398+hoangvvo@users.noreply.github.com> Date: Mon, 27 Apr 2020 09:25:00 -0400 Subject: [PATCH 09/27] typo --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index cd3d041..dc34c72 100644 --- a/package.json +++ b/package.json @@ -37,7 +37,7 @@ "@babel/runtime": "^7.9.2", "extract-files": "^8.0.0" }, - "peerDependencies: { + "peerDependencies": { "@apollo/client": "^3.0.0-beta.31" }, "devDependencies": { From da2c3011774bb37e29f7dd9692ef5fbef79cd159 Mon Sep 17 00:00:00 2001 From: Hoang Vo <40987398+hoangvvo@users.noreply.github.com> Date: Mon, 27 Apr 2020 09:35:18 -0400 Subject: [PATCH 10/27] linting and update deps --- package.json | 3 ++- src/index.js | 30 +++++++++++++++--------------- 2 files changed, 17 insertions(+), 16 deletions(-) diff --git a/package.json b/package.json index dc34c72..3572469 100644 --- a/package.json +++ b/package.json @@ -38,9 +38,10 @@ "extract-files": "^8.0.0" }, "peerDependencies": { - "@apollo/client": "^3.0.0-beta.31" + "@apollo/client": "^3.0.0-beta.44" }, "devDependencies": { + "@apollo/client": "^3.0.0-beta.44", "@babel/cli": "^7.8.4", "@babel/core": "^7.9.0", "@babel/plugin-transform-runtime": "^7.9.0", diff --git a/src/index.js b/src/index.js index 229ab73..125230a 100644 --- a/src/index.js +++ b/src/index.js @@ -8,11 +8,11 @@ const { serializeFetchParameter, createSignalIfSupported, parseAndCheckHttpResponse, - fromError -} = require('@apollo/client') + fromError, +} = require('@apollo/client'); const { - rewriteURIForGET -} = require('@apollo/client/link/http/rewriteURIForGET') + rewriteURIForGET, +} = require('@apollo/client/link/http/rewriteURIForGET'); const { extractFiles, isExtractableFile, @@ -183,7 +183,7 @@ exports.createUploadLink = ({ credentials, headers, includeExtensions, - useGETForQueries + useGETForQueries, } = {}) => { const linkConfig = { http: { includeExtensions }, @@ -192,9 +192,9 @@ exports.createUploadLink = ({ headers, }; - return new ApolloLink(operation => { - let uri = selectURI(operation, fetchUri) - const context = operation.getContext() + return new ApolloLink((operation) => { + let uri = selectURI(operation, fetchUri); + const context = operation.getContext(); // Apollo Graph Manager client awareness: // https://apollographql.com/docs/graph-manager/client-awareness @@ -252,24 +252,24 @@ exports.createUploadLink = ({ customFormDataAppendFile(form, ++i, file); }); - options.body = form + options.body = form; } else { // If requested, set method to GET if there are no mutations. if ( useGETForQueries && !operation.query.definitions.some( - definition => + (definition) => definition.kind === 'OperationDefinition' && definition.operation === 'mutation' ) ) - options.method = 'GET' + options.method = 'GET'; if (options.method === 'GET') { - const { newURI, parseError } = rewriteURIForGET(uri, body) - if (parseError) return fromError(parseError) - uri = newURI - } else options.body = payload + const { newURI, parseError } = rewriteURIForGET(uri, body); + if (parseError) return fromError(parseError); + uri = newURI; + } else options.body = payload; } return new Observable((observer) => { From de5c41dbdca9118e750051402aa0f6094407618d Mon Sep 17 00:00:00 2001 From: Hoang Vo <40987398+hoangvvo@users.noreply.github.com> Date: Sat, 6 Jun 2020 21:15:46 -0400 Subject: [PATCH 11/27] prepare for @apollo/client v3 --- package.json | 4 ++-- src/index.js | 4 +--- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/package.json b/package.json index 3572469..d69c7fe 100644 --- a/package.json +++ b/package.json @@ -38,10 +38,10 @@ "extract-files": "^8.0.0" }, "peerDependencies": { - "@apollo/client": "^3.0.0-beta.44" + "@apollo/client": "^3.0.0" }, "devDependencies": { - "@apollo/client": "^3.0.0-beta.44", + "@apollo/client": "^3.0.0", "@babel/cli": "^7.8.4", "@babel/core": "^7.9.0", "@babel/plugin-transform-runtime": "^7.9.0", diff --git a/src/index.js b/src/index.js index 125230a..c9b7534 100644 --- a/src/index.js +++ b/src/index.js @@ -9,10 +9,8 @@ const { createSignalIfSupported, parseAndCheckHttpResponse, fromError, -} = require('@apollo/client'); -const { rewriteURIForGET, -} = require('@apollo/client/link/http/rewriteURIForGET'); +} = require('@apollo/client'); const { extractFiles, isExtractableFile, From ad96df07ace0028146517ae0afe4a8f093a3a70e Mon Sep 17 00:00:00 2001 From: Jayden Seric Date: Tue, 14 Jul 2020 20:33:04 +1000 Subject: [PATCH 12/27] Move @apollo/client to dependencies and use a version that exists. --- package.json | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/package.json b/package.json index d69c7fe..51b8882 100644 --- a/package.json +++ b/package.json @@ -34,14 +34,11 @@ }, "browserslist": "Node >= 10, > 0.5%, not OperaMini all, not dead", "dependencies": { + "@apollo/client": "^3.0.0-rc.13", "@babel/runtime": "^7.9.2", "extract-files": "^8.0.0" }, - "peerDependencies": { - "@apollo/client": "^3.0.0" - }, "devDependencies": { - "@apollo/client": "^3.0.0", "@babel/cli": "^7.8.4", "@babel/core": "^7.9.0", "@babel/plugin-transform-runtime": "^7.9.0", From 3130c0dd70d8e94bb893b76ffeb24821ed71e472 Mon Sep 17 00:00:00 2001 From: Jayden Seric Date: Tue, 14 Jul 2020 20:37:20 +1000 Subject: [PATCH 13/27] Fix tests. --- .size-limit.json | 2 +- package.json | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/.size-limit.json b/.size-limit.json index 738af22..f2c4597 100644 --- a/.size-limit.json +++ b/.size-limit.json @@ -1,6 +1,6 @@ [ { "limit": "1.5 KB", - "ignore": ["apollo-link", "apollo-link-http-common"] + "ignore": ["@apollo/client"] } ] diff --git a/package.json b/package.json index 51b8882..221a53d 100644 --- a/package.json +++ b/package.json @@ -55,6 +55,7 @@ "graphql": "^14.6.0", "jsdoc-md": "^5.0.1", "prettier": "^2.0.2", + "react": "^16.13.1", "size-limit": "^4.4.2" }, "scripts": { From 675cbdec662f9a821b0584782a955be584e1b083 Mon Sep 17 00:00:00 2001 From: Jayden Seric Date: Tue, 14 Jul 2020 20:44:15 +1000 Subject: [PATCH 14/27] Remove broken support for GET requests. See https://github.com/jaydenseric/apollo-upload-client/pull/175#discussion_r373823519 . --- src/index.js | 25 +++---------------------- 1 file changed, 3 insertions(+), 22 deletions(-) diff --git a/src/index.js b/src/index.js index c9b7534..ef10a59 100644 --- a/src/index.js +++ b/src/index.js @@ -8,14 +8,13 @@ const { serializeFetchParameter, createSignalIfSupported, parseAndCheckHttpResponse, - fromError, - rewriteURIForGET, } = require('@apollo/client'); const { extractFiles, isExtractableFile, ReactNativeFile, } = require('extract-files'); + /** * A React Native [`File`](https://developer.mozilla.org/en-US/docs/Web/API/File) * substitute. @@ -181,7 +180,6 @@ exports.createUploadLink = ({ credentials, headers, includeExtensions, - useGETForQueries, } = {}) => { const linkConfig = { http: { includeExtensions }, @@ -191,7 +189,7 @@ exports.createUploadLink = ({ }; return new ApolloLink((operation) => { - let uri = selectURI(operation, fetchUri); + const uri = selectURI(operation, fetchUri); const context = operation.getContext(); // Apollo Graph Manager client awareness: @@ -251,24 +249,7 @@ exports.createUploadLink = ({ }); options.body = form; - } else { - // If requested, set method to GET if there are no mutations. - if ( - useGETForQueries && - !operation.query.definitions.some( - (definition) => - definition.kind === 'OperationDefinition' && - definition.operation === 'mutation' - ) - ) - options.method = 'GET'; - - if (options.method === 'GET') { - const { newURI, parseError } = rewriteURIForGET(uri, body); - if (parseError) return fromError(parseError); - uri = newURI; - } else options.body = payload; - } + } else options.body = payload; return new Observable((observer) => { // If no abort controller signal was provided in fetch options, and the From 331dfbed29c4a1721bde2ec7a0772e3efa414985 Mon Sep 17 00:00:00 2001 From: Jayden Seric Date: Tue, 14 Jul 2020 20:53:06 +1000 Subject: [PATCH 15/27] Add back removed whitespace. --- src/index.js | 1 + 1 file changed, 1 insertion(+) diff --git a/src/index.js b/src/index.js index 1e341ad..86de785 100644 --- a/src/index.js +++ b/src/index.js @@ -1,4 +1,5 @@ 'use strict'; + const { ApolloLink, Observable, From f2624a0eeb1c892f7e0a05cd11733417b49421db Mon Sep 17 00:00:00 2001 From: Jayden Seric Date: Tue, 14 Jul 2020 20:59:18 +1000 Subject: [PATCH 16/27] Update the changelog. --- changelog.md | 1 + 1 file changed, 1 insertion(+) diff --git a/changelog.md b/changelog.md index 6144fb6..b1b7c51 100644 --- a/changelog.md +++ b/changelog.md @@ -6,6 +6,7 @@ - Updated Node.js support to `^10.17.0 || ^12.0.0 || >= 13.7.0`. - Updated dependencies, some of which (only dev dependencies) require newer Node.js versions than previously supported. +- Support [`@apollo/client`](https://npm.im/@apollo/client) v3, fixing [#174](https://github.com/jaydenseric/apollo-upload-client/issues/174) via [#175](https://github.com/jaydenseric/apollo-upload-client/pull/175/files). ### Patch From 390e6e9407aa4a2f0c4ba5f7c7c53f24067a9f61 Mon Sep 17 00:00:00 2001 From: Jayden Seric Date: Tue, 14 Jul 2020 21:11:53 +1000 Subject: [PATCH 17/27] Update the peer dependencies to match @apollo/client v3 requirements. See https://github.com/jaydenseric/apollo-upload-client/pull/175#issuecomment-658118311 . --- package.json | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/package.json b/package.json index 7c3beb9..2cf9a5f 100644 --- a/package.json +++ b/package.json @@ -34,7 +34,9 @@ }, "browserslist": "Node 10.17 - 11 and Node < 11, Node 12 - 13 and Node < 13, Node >= 13.7, > 0.5%, not OperaMini all, not dead", "peerDependencies": { - "graphql": "^0.11.3 || ^0.12.3 || ^0.13.0 || ^14.0.0 || ^15.0.0" + "graphql": "14 - 15", + "react": "^16.8.0", + "subscriptions-transport-ws": "^0.9.0" }, "dependencies": { "@apollo/client": "^3.0.0-rc.13", From 41b1d869b7ec3da75f6ec80cb1d25a8364aff72e Mon Sep 17 00:00:00 2001 From: Jayden Seric Date: Tue, 14 Jul 2020 21:18:35 +1000 Subject: [PATCH 18/27] Remove the react peer dependency. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This package doesn’t use it directly, and it’s optional for @apollo/client. Including it in peer dependencies would undesirably require adding more ESLint/React related dev dependencies to satisfy eslint-config-env. --- package.json | 1 - 1 file changed, 1 deletion(-) diff --git a/package.json b/package.json index 2cf9a5f..8b4b2df 100644 --- a/package.json +++ b/package.json @@ -35,7 +35,6 @@ "browserslist": "Node 10.17 - 11 and Node < 11, Node 12 - 13 and Node < 13, Node >= 13.7, > 0.5%, not OperaMini all, not dead", "peerDependencies": { "graphql": "14 - 15", - "react": "^16.8.0", "subscriptions-transport-ws": "^0.9.0" }, "dependencies": { From b18916cc7878814780bff16ceaccb8290d46b3de Mon Sep 17 00:00:00 2001 From: Jayden Seric Date: Tue, 14 Jul 2020 21:22:15 +1000 Subject: [PATCH 19/27] Remove react from dev dependencies. --- package.json | 1 - 1 file changed, 1 deletion(-) diff --git a/package.json b/package.json index 8b4b2df..7abdd0e 100644 --- a/package.json +++ b/package.json @@ -59,7 +59,6 @@ "graphql": "^15.1.0", "jsdoc-md": "^7.0.0", "prettier": "^2.0.5", - "react": "^16.13.1", "size-limit": "^4.5.2" }, "scripts": { From 0eb7d1579a93a684571dc0bc2aee3d15afd775ce Mon Sep 17 00:00:00 2001 From: Hoang Vo <40987398+hoangvvo@users.noreply.github.com> Date: Tue, 14 Jul 2020 15:17:32 -0400 Subject: [PATCH 20/27] Use references from v3 --- readme.md | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) diff --git a/readme.md b/readme.md index bcabffe..afb5900 100644 --- a/readme.md +++ b/readme.md @@ -4,7 +4,7 @@ [![npm version](https://badgen.net/npm/v/apollo-upload-client)](https://npm.im/apollo-upload-client) [![CI status](https://github.com/jaydenseric/apollo-upload-client/workflows/CI/badge.svg)](https://github.com/jaydenseric/apollo-upload-client/actions) -A terminating [Apollo Link](https://apollographql.com/docs/link) for [Apollo Client](https://apollographql.com/docs/link/#apollo-client) that allows [`FileList`](https://developer.mozilla.org/en-US/docs/Web/API/FileList), [`File`](https://developer.mozilla.org/en-US/docs/Web/API/File), [`Blob`](https://developer.mozilla.org/en-US/docs/Web/API/Blob) or [`ReactNativeFile`](#class-reactnativefile) instances within query or mutation variables and sends [GraphQL multipart requests](https://github.com/jaydenseric/graphql-multipart-request-spec). +A terminating [Apollo Link](https://www.apollographql.com/docs/react/api/link/introduction/) for [Apollo Client](https://www.apollographql.com/docs/react/) that allows [`FileList`](https://developer.mozilla.org/en-US/docs/Web/API/FileList), [`File`](https://developer.mozilla.org/en-US/docs/Web/API/File), [`Blob`](https://developer.mozilla.org/en-US/docs/Web/API/Blob) or [`ReactNativeFile`](#class-reactnativefile) instances within query or mutation variables and sends [GraphQL multipart requests](https://github.com/jaydenseric/graphql-multipart-request-spec). ## Setup @@ -14,9 +14,7 @@ Install with [npm](https://npmjs.com): npm install apollo-upload-client ``` -[Apollo Boost](https://npm.im/apollo-boost) doesn’t allow link customization; if you are using it [migrate to a manual Apollo Client setup](https://apollographql.com/docs/react/migrating/boost-migration). - -[Apollo Client](https://apollographql.com/docs/link/#apollo-client) can only have 1 “terminating” [Apollo Link](https://apollographql.com/docs/link) that sends the GraphQL requests; if one such as [`apollo-link-http`](https://apollographql.com/docs/link/links/http) is already setup, remove it. +[Apollo Client](https://www.apollographql.com/docs/react/) can only have 1 [terminating link](https://www.apollographql.com/docs/react/api/link/introduction/#the-terminating-link) that sends the GraphQL requests; if one such as [`apollo-link-http`](https://apollographql.com/docs/link/links/http) is already setup, remove it. Initialize the client with a terminating link using [`createUploadLink`](#function-createuploadlink). @@ -31,8 +29,7 @@ See also the [example API and client](https://github.com/jaydenseric/apollo-uplo ### [`FileList`](https://developer.mozilla.org/en-US/docs/Web/API/FileList) ```jsx -const { useMutation } = require('@apollo/react-hooks'); -const gql = require('graphql-tag'); +const { gql, useMutation } = require('@apollo/client'); const MUTATION = gql` mutation($files: [Upload!]!) { @@ -56,8 +53,7 @@ function UploadFiles() { ### [`File`](https://developer.mozilla.org/en-US/docs/Web/API/File) ```jsx -const { useMutation } = require('@apollo/react-hooks'); -const gql = require('graphql-tag'); +const { gql, useMutation } = require('@apollo/client'); const MUTATION = gql` mutation($file: Upload!) { @@ -86,8 +82,7 @@ function UploadFile() { ### [`Blob`](https://developer.mozilla.org/en-US/docs/Web/API/Blob) ```jsx -const { useMutation } = require('@apollo/react-hooks'); -const gql = require('graphql-tag'); +const { gql, useMutation } = require('@apollo/client'); const MUTATION = gql` mutation($file: Upload!) { @@ -201,8 +196,7 @@ Some of the options are similar to the [`createHttpLink` options](https://apollo _A basic Apollo Client setup._ > ```js -> const { ApolloClient } = require('apollo-client'); -> const { InMemoryCache } = require('apollo-cache-inmemory'); +> const { ApolloClient, InMemoryCache } = require('@apollo/client'); > const { createUploadLink } = require('apollo-upload-client'); > > const client = new ApolloClient({ From 829afe9a6c1c52c227f8d026828dcda29c745bca Mon Sep 17 00:00:00 2001 From: Hoang <40987398+hoangvvo@users.noreply.github.com> Date: Tue, 14 Jul 2020 15:28:51 -0400 Subject: [PATCH 21/27] Bump@apollo/client version in dep MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Michaël De Boey --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 7abdd0e..7ac29a6 100644 --- a/package.json +++ b/package.json @@ -38,7 +38,7 @@ "subscriptions-transport-ws": "^0.9.0" }, "dependencies": { - "@apollo/client": "^3.0.0-rc.13", + "@apollo/client": "^3.0.0", "@babel/runtime": "^7.10.3", "extract-files": "^8.1.0" }, From 683cc966e8041379b644602fedd4a96c679e52f1 Mon Sep 17 00:00:00 2001 From: Hoang <40987398+hoangvvo@users.noreply.github.com> Date: Tue, 14 Jul 2020 15:35:01 -0400 Subject: [PATCH 22/27] Match `apollo-client` peer deps MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Michaël De Boey --- package.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 7ac29a6..1655787 100644 --- a/package.json +++ b/package.json @@ -34,8 +34,8 @@ }, "browserslist": "Node 10.17 - 11 and Node < 11, Node 12 - 13 and Node < 13, Node >= 13.7, > 0.5%, not OperaMini all, not dead", "peerDependencies": { - "graphql": "14 - 15", - "subscriptions-transport-ws": "^0.9.0" + "graphql": ">=14.0.0", + "subscriptions-transport-ws": ">=0.9.0" }, "dependencies": { "@apollo/client": "^3.0.0", From cae60e1c3381ee1f554b7da06099f792017e4d33 Mon Sep 17 00:00:00 2001 From: Hoang Vo <40987398+hoangvvo@users.noreply.github.com> Date: Tue, 14 Jul 2020 15:46:41 -0400 Subject: [PATCH 23/27] Add notes on `uri`, `headers`, and `credentials` --- readme.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/readme.md b/readme.md index afb5900..ed80183 100644 --- a/readme.md +++ b/readme.md @@ -14,7 +14,7 @@ Install with [npm](https://npmjs.com): npm install apollo-upload-client ``` -[Apollo Client](https://www.apollographql.com/docs/react/) can only have 1 [terminating link](https://www.apollographql.com/docs/react/api/link/introduction/#the-terminating-link) that sends the GraphQL requests; if one such as [`apollo-link-http`](https://apollographql.com/docs/link/links/http) is already setup, remove it. +[Apollo Client](https://www.apollographql.com/docs/react/) can only have 1 [terminating link](https://www.apollographql.com/docs/react/api/link/introduction/#the-terminating-link) that sends the GraphQL requests; if one such as `HttpLink` is already setup, remove it. Instead of adding the options `uri`, `headers` and `credentials` in the `ApolloClient` constructor, do so in [`createUploadLink`](#function-createuploadlink). Initialize the client with a terminating link using [`createUploadLink`](#function-createuploadlink). From 1b80eaf46ee8934c157428035c9c4e3e71d092d3 Mon Sep 17 00:00:00 2001 From: Jayden Seric Date: Wed, 15 Jul 2020 09:42:44 +1000 Subject: [PATCH 24/27] Revert "Match `apollo-client` peer deps" This reverts commit 683cc966e8041379b644602fedd4a96c679e52f1. See https://github.com/jaydenseric/apollo-upload-client/pull/201#issuecomment-657916102 . --- package.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 1655787..7ac29a6 100644 --- a/package.json +++ b/package.json @@ -34,8 +34,8 @@ }, "browserslist": "Node 10.17 - 11 and Node < 11, Node 12 - 13 and Node < 13, Node >= 13.7, > 0.5%, not OperaMini all, not dead", "peerDependencies": { - "graphql": ">=14.0.0", - "subscriptions-transport-ws": ">=0.9.0" + "graphql": "14 - 15", + "subscriptions-transport-ws": "^0.9.0" }, "dependencies": { "@apollo/client": "^3.0.0", From 2bdd2a4e6cac18eea56fe877535d5189e09a2014 Mon Sep 17 00:00:00 2001 From: Jayden Seric Date: Wed, 15 Jul 2020 14:10:34 +1000 Subject: [PATCH 25/27] Documentation tweaks and fixes. --- changelog.md | 2 +- readme.md | 12 ++++++------ src/index.js | 7 +++---- 3 files changed, 10 insertions(+), 11 deletions(-) diff --git a/changelog.md b/changelog.md index b1b7c51..b909228 100644 --- a/changelog.md +++ b/changelog.md @@ -402,7 +402,7 @@ ## 3.0.0 -- Support `apollo-upload-server` v2 and [query batching](https://apollographql.com/docs/apollo-server/requests#batching). +- Support `apollo-upload-server` v2 and [query batching](https://apollographql.com/docs/apollo-server/requests/#batching). - Removed the seemingly redundant `Accept` header from requests. - Clearer package description. diff --git a/readme.md b/readme.md index ed80183..84d7121 100644 --- a/readme.md +++ b/readme.md @@ -4,7 +4,7 @@ [![npm version](https://badgen.net/npm/v/apollo-upload-client)](https://npm.im/apollo-upload-client) [![CI status](https://github.com/jaydenseric/apollo-upload-client/workflows/CI/badge.svg)](https://github.com/jaydenseric/apollo-upload-client/actions) -A terminating [Apollo Link](https://www.apollographql.com/docs/react/api/link/introduction/) for [Apollo Client](https://www.apollographql.com/docs/react/) that allows [`FileList`](https://developer.mozilla.org/en-US/docs/Web/API/FileList), [`File`](https://developer.mozilla.org/en-US/docs/Web/API/File), [`Blob`](https://developer.mozilla.org/en-US/docs/Web/API/Blob) or [`ReactNativeFile`](#class-reactnativefile) instances within query or mutation variables and sends [GraphQL multipart requests](https://github.com/jaydenseric/graphql-multipart-request-spec). +A [terminating Apollo Link](https://apollographql.com/docs/link/overview/#terminating-links) for [Apollo Client](https://apollographql.com/docs/react) that allows [`FileList`](https://developer.mozilla.org/en-US/docs/Web/API/FileList), [`File`](https://developer.mozilla.org/en-US/docs/Web/API/File), [`Blob`](https://developer.mozilla.org/en-US/docs/Web/API/Blob) or [`ReactNativeFile`](#class-reactnativefile) instances within query or mutation variables and sends [GraphQL multipart requests](https://github.com/jaydenseric/graphql-multipart-request-spec). ## Setup @@ -14,9 +14,9 @@ Install with [npm](https://npmjs.com): npm install apollo-upload-client ``` -[Apollo Client](https://www.apollographql.com/docs/react/) can only have 1 [terminating link](https://www.apollographql.com/docs/react/api/link/introduction/#the-terminating-link) that sends the GraphQL requests; if one such as `HttpLink` is already setup, remove it. Instead of adding the options `uri`, `headers` and `credentials` in the `ApolloClient` constructor, do so in [`createUploadLink`](#function-createuploadlink). +[Apollo Client](https://apollographql.com/docs/react) can only have 1 [terminating Apollo Link](https://apollographql.com/docs/link/overview/#terminating-links) that sends the GraphQL requests; if one such as [`HttpLink`](https://apollographql.com/docs/link/links/http) is already setup, remove it. Instead of adding the options `uri`, `headers` and `credentials` in the `ApolloClient` constructor, do so in [`createUploadLink`](#function-createuploadlink). -Initialize the client with a terminating link using [`createUploadLink`](#function-createuploadlink). +Initialize the client with a [terminating Apollo Link](https://apollographql.com/docs/link/overview/#terminating-links) using [`createUploadLink`](#function-createuploadlink). Also ensure the GraphQL server implements the [GraphQL multipart request spec](https://github.com/jaydenseric/graphql-multipart-request-spec) and that uploads are handled correctly in resolvers. @@ -165,7 +165,7 @@ _A React Native file that can be used in query or mutation variables._ ### function createUploadLink -Creates a terminating [Apollo Link](https://apollographql.com/docs/link) capable of file uploads. +Creates a [terminating Apollo Link](https://apollographql.com/docs/link/overview/#terminating-links) capable of file uploads. The link matches and extracts files in the GraphQL operation. If there are files it uses a [`FormData`](https://developer.mozilla.org/en-US/docs/Web/API/FormData) instance as the [`fetch`](https://developer.mozilla.org/en-US/docs/Web/API/WindowOrWorkerGlobalScope/fetch) `options.body` to make a [GraphQL multipart request](https://github.com/jaydenseric/graphql-multipart-request-spec), otherwise it sends a regular POST request. @@ -184,7 +184,7 @@ Some of the options are similar to the [`createHttpLink` options](https://apollo | `options.headers` | object? | Merges with and overrides `options.fetchOptions.headers`. | | `options.includeExtensions` | boolean? = `false` | Toggles sending `extensions` fields to the GraphQL server. | -**Returns:** ApolloLink — A terminating [Apollo Link](https://apollographql.com/docs/link) capable of file uploads. +**Returns:** ApolloLink — A [terminating Apollo Link](https://apollographql.com/docs/link/overview/#terminating-links) capable of file uploads. #### See @@ -196,7 +196,7 @@ Some of the options are similar to the [`createHttpLink` options](https://apollo _A basic Apollo Client setup._ > ```js -> const { ApolloClient, InMemoryCache } = require('@apollo/client'); +> const { ApolloClient, InMemoryCache } = require('@apollo/client'); > const { createUploadLink } = require('apollo-upload-client'); > > const client = new ApolloClient({ diff --git a/src/index.js b/src/index.js index 86de785..f24bd70 100644 --- a/src/index.js +++ b/src/index.js @@ -135,7 +135,7 @@ function formDataAppendFile(formData, fieldName, file) { exports.formDataAppendFile = formDataAppendFile; /** - * Creates a terminating [Apollo Link](https://apollographql.com/docs/link) + * Creates a [terminating Apollo Link](https://apollographql.com/docs/link/overview/#terminating-links) * capable of file uploads. * * The link matches and extracts files in the GraphQL operation. If there are @@ -159,11 +159,10 @@ exports.formDataAppendFile = formDataAppendFile; * @param {string} [options.credentials] Overrides `options.fetchOptions.credentials`. * @param {object} [options.headers] Merges with and overrides `options.fetchOptions.headers`. * @param {boolean} [options.includeExtensions=false] Toggles sending `extensions` fields to the GraphQL server. - * @returns {ApolloLink} A terminating [Apollo Link](https://apollographql.com/docs/link) capable of file uploads. + * @returns {ApolloLink} A [terminating Apollo Link](https://apollographql.com/docs/link/overview/#terminating-links) capable of file uploads. * @example A basic Apollo Client setup. * ```js - * const { ApolloClient } = require('apollo-client'); - * const { InMemoryCache } = require('apollo-cache-inmemory'); + * const { ApolloClient, InMemoryCache } = require('@apollo/client'); * const { createUploadLink } = require('apollo-upload-client'); * * const client = new ApolloClient({ From d14700f3cb579f13b629c159b55f6fbb2acb8995 Mon Sep 17 00:00:00 2001 From: Jayden Seric Date: Wed, 15 Jul 2020 16:02:17 +1000 Subject: [PATCH 26/27] Improve the setup instructions. --- readme.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/readme.md b/readme.md index 84d7121..4756d6f 100644 --- a/readme.md +++ b/readme.md @@ -14,7 +14,9 @@ Install with [npm](https://npmjs.com): npm install apollo-upload-client ``` -[Apollo Client](https://apollographql.com/docs/react) can only have 1 [terminating Apollo Link](https://apollographql.com/docs/link/overview/#terminating-links) that sends the GraphQL requests; if one such as [`HttpLink`](https://apollographql.com/docs/link/links/http) is already setup, remove it. Instead of adding the options `uri`, `headers` and `credentials` in the `ApolloClient` constructor, do so in [`createUploadLink`](#function-createuploadlink). +Remove any `uri`, `credentials`, or `headers` options from the [`ApolloClient` constructor](https://www.apollographql.com/docs/react/api/core/ApolloClient/#the-apolloclient-constructor). + +[Apollo Client](https://apollographql.com/docs/react) can only have 1 [terminating Apollo Link](https://apollographql.com/docs/link/overview/#terminating-links) that sends the GraphQL requests; if one such as [`HttpLink`](https://apollographql.com/docs/link/links/http) is already setup, remove it. Initialize the client with a [terminating Apollo Link](https://apollographql.com/docs/link/overview/#terminating-links) using [`createUploadLink`](#function-createuploadlink). From fb62f6b4b1b23733964e216de06bdbd3460f3b93 Mon Sep 17 00:00:00 2001 From: Jayden Seric Date: Wed, 15 Jul 2020 16:07:02 +1000 Subject: [PATCH 27/27] Fix example code formatting. --- src/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/index.js b/src/index.js index f24bd70..842484c 100644 --- a/src/index.js +++ b/src/index.js @@ -162,7 +162,7 @@ exports.formDataAppendFile = formDataAppendFile; * @returns {ApolloLink} A [terminating Apollo Link](https://apollographql.com/docs/link/overview/#terminating-links) capable of file uploads. * @example A basic Apollo Client setup. * ```js - * const { ApolloClient, InMemoryCache } = require('@apollo/client'); + * const { ApolloClient, InMemoryCache } = require('@apollo/client'); * const { createUploadLink } = require('apollo-upload-client'); * * const client = new ApolloClient({