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

Support Apollo Client v3 #175

Merged
merged 29 commits into from Jul 15, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
f318ef8
Use apollo-client v3
hoangvvo Feb 1, 2020
7b4e4b3
Support GET requests
hoangvvo Feb 1, 2020
61d4007
Fix abort controller
hoangvvo Feb 1, 2020
26206e7
remove dup
hoangvvo Feb 2, 2020
5a513c2
Update package.json
hoangvvo Feb 3, 2020
e929208
revert
hoangvvo Feb 3, 2020
39256a0
Move fn into .some
hoangvvo Feb 3, 2020
6bd7cce
Merge branch 'master' into apollo-client-v3
hoangvvo Apr 27, 2020
5eb2034
typo
hoangvvo Apr 27, 2020
a4cf534
typo
hoangvvo Apr 27, 2020
da2c301
linting and update deps
hoangvvo Apr 27, 2020
de5c41d
prepare for @apollo/client v3
hoangvvo Jun 7, 2020
ad96df0
Move @apollo/client to dependencies and use a version that exists.
jaydenseric Jul 14, 2020
3130c0d
Fix tests.
jaydenseric Jul 14, 2020
675cbde
Remove broken support for GET requests.
jaydenseric Jul 14, 2020
2a71bce
Merge branch 'master' into hoangvvo/apollo-client-v3
jaydenseric Jul 14, 2020
331dfbe
Add back removed whitespace.
jaydenseric Jul 14, 2020
f2624a0
Update the changelog.
jaydenseric Jul 14, 2020
390e6e9
Update the peer dependencies to match @apollo/client v3 requirements.
jaydenseric Jul 14, 2020
41b1d86
Remove the react peer dependency.
jaydenseric Jul 14, 2020
b18916c
Remove react from dev dependencies.
jaydenseric Jul 14, 2020
0eb7d15
Use references from v3
hoangvvo Jul 14, 2020
829afe9
Bump@apollo/client version in dep
hoangvvo Jul 14, 2020
683cc96
Match `apollo-client` peer deps
hoangvvo Jul 14, 2020
cae60e1
Add notes on `uri`, `headers`, and `credentials`
hoangvvo Jul 14, 2020
1b80eaf
Revert "Match `apollo-client` peer deps"
jaydenseric Jul 14, 2020
2bdd2a4
Documentation tweaks and fixes.
jaydenseric Jul 15, 2020
d14700f
Improve the setup instructions.
jaydenseric Jul 15, 2020
fb62f6b
Fix example code formatting.
jaydenseric Jul 15, 2020
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 .size-limit.json
@@ -1,6 +1,6 @@
[
{
"limit": "1.5 KB",
"ignore": ["apollo-link", "apollo-link-http-common"]
"ignore": ["@apollo/client"]
}
]
3 changes: 2 additions & 1 deletion changelog.md
Expand Up @@ -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

Expand Down Expand Up @@ -401,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.

Expand Down
6 changes: 3 additions & 3 deletions package.json
Expand Up @@ -34,12 +34,12 @@
},
"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",
"subscriptions-transport-ws": "^0.9.0"
hoangvvo marked this conversation as resolved.
Show resolved Hide resolved
},
"dependencies": {
"@apollo/client": "^3.0.0",
"@babel/runtime": "^7.10.3",
"apollo-link": "^1.2.14",
"apollo-link-http-common": "^0.2.16",
"extract-files": "^8.1.0"
},
"devDependencies": {
Expand Down
24 changes: 10 additions & 14 deletions readme.md
Expand Up @@ -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://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

Expand All @@ -14,11 +14,11 @@ 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).
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/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://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 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.

Expand All @@ -31,8 +31,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!]!) {
Expand All @@ -56,8 +55,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!) {
Expand Down Expand Up @@ -86,8 +84,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!) {
Expand Down Expand Up @@ -170,7 +167,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.

Expand All @@ -189,7 +186,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

Expand All @@ -201,8 +198,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({
Expand Down
12 changes: 6 additions & 6 deletions src/index.js
@@ -1,14 +1,15 @@
'use strict';

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,
isExtractableFile,
Expand Down Expand Up @@ -134,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
Expand All @@ -158,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 <caption>A basic Apollo Client setup.</caption>
* ```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({
Expand Down