Skip to content

Commit 2b6c813

Browse files
authoredOct 27, 2020
Update links package to use @apollo/client/links (#2138)
* fix(utils): fix typing mismatch between linkToSubscriber and observableToAsyncIterable * feat(links): AC3 support * fix(url-loader): fix typing mismatch * Fix build * Update TypeScript * try something * ignore engines
1 parent e2b1eac commit 2b6c813

16 files changed

+99
-53
lines changed
 

‎.changeset/new-pears-compete.md

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
---
2+
'@graphql-tools/links': major
3+
---
4+
5+
feat(links): AC3 support
6+
7+
`apollo-link` has been deprecated so this package now uses `@apollo/client` as peer dependency;
8+
You can [see more on migration guide.](https://www.apollographql.com/docs/react/migrating/apollo-client-3-migration/#apollo-link-and-apollo-link-http)

‎.changeset/thin-ways-wave.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@graphql-tools/utils': patch
3+
---
4+
5+
fix(utils): fix typing mismatch between linkToSubscriber and observableToAsyncIterable

‎.github/workflows/canary.yml

+4-4
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ jobs:
1616
- name: Use Node
1717
uses: actions/setup-node@v1
1818
with:
19-
node-version: '14.x'
19+
node-version: '15.x'
2020
- name: Configure Git Credentials
2121
run: |
2222
git config --global user.email "theguild-bot@users.noreply.github.com"
@@ -33,11 +33,11 @@ jobs:
3333
uses: actions/cache@v1
3434
with:
3535
path: ${{ steps.yarn-cache.outputs.dir }}
36-
key: ${{ runner.os }}-14-15-yarn-${{ hashFiles('yarn.lock') }}
36+
key: ${{ runner.os }}-15-15-yarn-${{ hashFiles('yarn.lock') }}
3737
restore-keys: |
38-
${{ runner.os }}-14-15-yarn-
38+
${{ runner.os }}-15-15-yarn-
3939
- name: Install Dependencies using Yarn
40-
run: yarn install && git checkout yarn.lock
40+
run: yarn install --ignore-engines && git checkout yarn.lock
4141
- name: Release Canary
4242
id: canary
4343
uses: 'kamilkisiela/release-canary@master'

‎.github/workflows/release.yml

+4-4
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ jobs:
2424
- name: Use Node
2525
uses: actions/setup-node@v1
2626
with:
27-
node-version: '14.x'
27+
node-version: '15.x'
2828
- name: Setup NPM credentials
2929
run: echo "//registry.npmjs.org/:_authToken=$NODE_AUTH_TOKEN" >> ~/.npmrc
3030
env:
@@ -36,11 +36,11 @@ jobs:
3636
uses: actions/cache@v1
3737
with:
3838
path: ${{ steps.yarn-cache.outputs.dir }}
39-
key: ${{ runner.os }}-14-15-yarn-${{ hashFiles('yarn.lock') }}
39+
key: ${{ runner.os }}-15-15-yarn-${{ hashFiles('yarn.lock') }}
4040
restore-keys: |
41-
${{ runner.os }}-14-15-yarn-
41+
${{ runner.os }}-15-15-yarn-
4242
- name: Install Dependencies using Yarn
43-
run: yarn install && git checkout yarn.lock
43+
run: yarn install --ignore-engines && git checkout yarn.lock
4444
- name: Build
4545
run: yarn build
4646
- name: Create Release Pull Request or Publish to npm

‎.github/workflows/tests.yml

+7-7
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@ jobs:
1515
steps:
1616
- name: Checkout Master
1717
uses: actions/checkout@v1
18-
- name: Use Node 14
18+
- name: Use Node 15
1919
uses: actions/setup-node@master
2020
with:
21-
node-version: 14
21+
node-version: 15
2222
- name: Get yarn cache
2323
id: yarn-cache
2424
run: echo "::set-output name=dir::$(yarn cache dir)"
@@ -30,7 +30,7 @@ jobs:
3030
restore-keys: |
3131
${{ runner.os }}-${{matrix.node_version}}-${{matrix.graphql_version}}-yarn
3232
- name: Install Dependencies using Yarn
33-
run: yarn install && git checkout yarn.lock
33+
run: yarn install --ignore-engines && git checkout yarn.lock
3434
- name: Lint
3535
run: yarn lint
3636
build:
@@ -45,7 +45,7 @@ jobs:
4545
- name: Use Node 14
4646
uses: actions/setup-node@master
4747
with:
48-
node-version: 14
48+
node-version: 15
4949
- name: Get yarn cache
5050
id: yarn-cache
5151
run: echo "::set-output name=dir::$(yarn cache dir)"
@@ -59,7 +59,7 @@ jobs:
5959
- name: Use GraphQL v${{matrix.graphql_version}}
6060
run: node ./scripts/match-graphql.js ${{matrix.graphql_version}}
6161
- name: Install Dependencies using Yarn
62-
run: yarn install && git checkout yarn.lock
62+
run: yarn install --ignore-engines && git checkout yarn.lock
6363
- name: Build
6464
run: yarn ts:transpile
6565
test:
@@ -68,7 +68,7 @@ jobs:
6868
strategy:
6969
matrix:
7070
os: [ubuntu-latest, windows-latest]
71-
node_version: [10, 14]
71+
node_version: [10, 15]
7272
graphql_version: [14, 15]
7373
steps:
7474
- name: Checkout Master
@@ -90,7 +90,7 @@ jobs:
9090
- name: Use GraphQL v${{matrix.graphql_version}}
9191
run: node ./scripts/match-graphql.js ${{matrix.graphql_version}}
9292
- name: Install Dependencies using Yarn
93-
run: yarn install && git checkout yarn.lock
93+
run: yarn install --ignore-engines && git checkout yarn.lock
9494
- name: Cache Jest
9595
uses: actions/cache@v1
9696
with:

‎.github/workflows/website.yml

+4-4
Original file line numberDiff line numberDiff line change
@@ -27,19 +27,19 @@ jobs:
2727
- name: Use Node
2828
uses: actions/setup-node@v1
2929
with:
30-
node-version: '14.x'
30+
node-version: '15.x'
3131
- name: Get yarn cache
3232
id: yarn-cache
3333
run: echo "::set-output name=dir::$(yarn cache dir)"
3434
- name: Cache Yarn
3535
uses: actions/cache@v1
3636
with:
3737
path: ${{ steps.yarn-cache.outputs.dir }}
38-
key: ${{ runner.os }}-14-15-yarn-${{ hashFiles('yarn.lock') }}
38+
key: ${{ runner.os }}-15-15-yarn-${{ hashFiles('yarn.lock') }}
3939
restore-keys: |
40-
${{ runner.os }}-14-15-yarn-
40+
${{ runner.os }}-15-15-yarn-
4141
- name: Install Dependencies using Yarn
42-
run: yarn install && git checkout yarn.lock
42+
run: yarn install --ignore-engines && git checkout yarn.lock
4343
- name: Deploy 🚀
4444
run: yarn deploy:website
4545
env:

‎package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@
6767
"ts-jest": "26.4.1",
6868
"typedoc": "0.17.0-3",
6969
"typedoc-plugin-markdown": "2.3.1",
70-
"typescript": "4.0.3"
70+
"typescript": "4.0.5"
7171
},
7272
"husky": {
7373
"hooks": {

‎packages/links/package.json

+10-4
Original file line numberDiff line numberDiff line change
@@ -12,19 +12,25 @@
1212
"definition": "dist/index.d.ts"
1313
},
1414
"peerDependencies": {
15-
"graphql": "^14.0.0 || ^15.0.0"
15+
"graphql": "^14.0.0 || ^15.0.0",
16+
"@apollo/client": "~3.2.5"
1617
},
1718
"buildOptions": {
18-
"input": "./src/index.ts"
19+
"input": "./src/index.ts",
20+
"external": [
21+
"@apollo/client/link/core",
22+
"@apollo/client/link/utils",
23+
"@apollo/client/utilities"
24+
]
1925
},
2026
"devDependencies": {
27+
"@apollo/client": "3.2.5",
2128
"@types/graphql-upload": "8.0.4",
2229
"express-graphql": "0.11.0",
2330
"graphql-upload": "11.0.0"
2431
},
2532
"dependencies": {
26-
"@graphql-tools/utils": "^7.0.0",
27-
"apollo-link": "1.2.14",
33+
"@graphql-tools/utils": "7.0.0",
2834
"apollo-upload-client": "14.1.2",
2935
"cross-fetch": "3.0.6",
3036
"form-data": "3.0.0",

‎packages/links/src/AwaitVariablesLink.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
import { ApolloLink, Operation, NextLink, Observable, FetchResult } from 'apollo-link';
1+
import { ApolloLink, FetchResult, NextLink, Operation } from '@apollo/client/link/core';
2+
import { Observable } from '@apollo/client/utilities';
23

34
function getFinalPromise(object: any): Promise<any> {
45
return Promise.resolve(object).then(resolvedObject => {

‎packages/links/src/createServerHttpLink.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { concat } from 'apollo-link';
1+
import { concat } from '@apollo/client/link/core';
22
import { createUploadLink, formDataAppendFile, isExtractableFile } from 'apollo-upload-client';
33
import FormData, { AppendOptions } from 'form-data';
44
import { fetch } from 'cross-fetch';

‎packages/links/src/linkToExecutor.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
import { ApolloLink, toPromise, execute, Observable, FetchResult } from 'apollo-link';
1+
import { ApolloLink, execute, FetchResult } from '@apollo/client/link/core';
2+
import { Observable } from '@apollo/client/utilities';
3+
import { toPromise } from '@apollo/client/link/utils';
24
import { DocumentNode, GraphQLResolveInfo } from 'graphql';
35

46
export const linkToExecutor = (link: ApolloLink) => <TReturn, TArgs, TContext>({

‎packages/links/src/linkToSubscriber.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
import { ApolloLink, execute, FetchResult, Observable } from 'apollo-link';
1+
import { ApolloLink, execute, FetchResult } from '@apollo/client/link/core';
2+
import { Observable } from '@apollo/client/utilities';
23
import { observableToAsyncIterable } from '@graphql-tools/utils';
34
import { GraphQLResolveInfo, DocumentNode } from 'graphql';
45

‎packages/loaders/url/src/index.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ export class UrlLoader implements DocumentLoader<LoadFromUrlOptions> {
148148
query: document,
149149
variables,
150150
})
151-
) as AsyncIterator<ExecutionResult<TReturn>>;
151+
) as AsyncIterableIterator<ExecutionResult<TReturn>>;
152152
};
153153
}
154154

‎packages/utils/src/observableToAsyncIterable.ts

+14-17
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,7 @@ export interface Observable<T> {
1414

1515
export type Callback = (value?: any) => any;
1616

17-
export function observableToAsyncIterable<T>(
18-
observable: Observable<T>
19-
): AsyncIterator<T> & {
20-
[Symbol.asyncIterator]: () => AsyncIterator<T>;
21-
} {
17+
export function observableToAsyncIterable<T>(observable: Observable<T>): AsyncIterable<T> {
2218
const pullQueue: Array<Callback> = [];
2319
const pushQueue: Array<any> = [];
2420

@@ -74,19 +70,20 @@ export function observableToAsyncIterable<T>(
7470
};
7571

7672
return {
77-
next() {
78-
return listening ? pullValue() : this.return();
79-
},
80-
return() {
81-
emptyQueue();
82-
return Promise.resolve({ value: undefined, done: true });
83-
},
84-
throw(error) {
85-
emptyQueue();
86-
return Promise.reject(error);
87-
},
8873
[Symbol.asyncIterator]() {
89-
return this;
74+
return {
75+
next() {
76+
return listening ? pullValue() : this.return();
77+
},
78+
return() {
79+
emptyQueue();
80+
return Promise.resolve({ value: undefined, done: true });
81+
},
82+
throw(error) {
83+
emptyQueue();
84+
return Promise.reject(error);
85+
},
86+
};
9087
},
9188
};
9289
}

‎packages/wrap/src/transforms/HoistField.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -119,14 +119,14 @@ export default class HoistField implements Transform {
119119

120120
Object.keys(targetField.args).forEach(argName => {
121121
const argConfig = targetField.args[argName];
122-
const arg: GraphQLArgument = {
122+
const arg = {
123123
...argConfig,
124124
name: argName,
125125
description: argConfig.description,
126126
defaultValue: argConfig.defaultValue,
127127
extensions: argConfig.extensions,
128128
astNode: argConfig.astNode,
129-
};
129+
} as GraphQLArgument;
130130
if (this.argFilters[level](arg)) {
131131
argsMap[argName] = arg;
132132
this.argLevels[arg.name] = level;

‎yarn.lock

+31-5
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,25 @@
106106
"@algolia/logger-common" "4.5.1"
107107
"@algolia/requester-common" "4.5.1"
108108

109+
"@apollo/client@3.2.5":
110+
version "3.2.5"
111+
resolved "https://registry.yarnpkg.com/@apollo/client/-/client-3.2.5.tgz#24e0a6faa1d231ab44807af237c6227410c75c4d"
112+
integrity sha512-zpruxnFMz6K94gs2pqc3sidzFDbQpKT5D6P/J/I9s8ekHZ5eczgnRp6pqXC86Bh7+44j/btpmOT0kwiboyqTnA==
113+
dependencies:
114+
"@graphql-typed-document-node/core" "^3.0.0"
115+
"@types/zen-observable" "^0.8.0"
116+
"@wry/context" "^0.5.2"
117+
"@wry/equality" "^0.2.0"
118+
fast-json-stable-stringify "^2.0.0"
119+
graphql-tag "^2.11.0"
120+
hoist-non-react-statics "^3.3.2"
121+
optimism "^0.13.0"
122+
prop-types "^15.7.2"
123+
symbol-observable "^2.0.0"
124+
ts-invariant "^0.4.4"
125+
tslib "^1.10.0"
126+
zen-observable "^0.8.14"
127+
109128
"@apollo/client@^3.1.5":
110129
version "3.2.2"
111130
resolved "https://registry.yarnpkg.com/@apollo/client/-/client-3.2.2.tgz#fe5cad4d53373979f13a925e9da02d8743e798a5"
@@ -3357,7 +3376,7 @@ apollo-graphql@^0.6.0:
33573376
apollo-env "^0.6.5"
33583377
lodash.sortby "^4.7.0"
33593378

3360-
apollo-link@1.2.14, apollo-link@^1.2.14:
3379+
apollo-link@^1.2.14:
33613380
version "1.2.14"
33623381
resolved "https://registry.yarnpkg.com/apollo-link/-/apollo-link-1.2.14.tgz#3feda4b47f9ebba7f4160bef8b977ba725b684d9"
33633382
integrity sha512-p67CMEFP7kOG1JZ0ZkYZwRDa369w5PIjtMjvrQd/HnIV8FRsHRqLqK+oAZQnFa1DDdZtOtHTi+aMIW6EatC2jg==
@@ -10567,6 +10586,13 @@ optimism@^0.12.1:
1056710586
dependencies:
1056810587
"@wry/context" "^0.5.2"
1056910588

10589+
optimism@^0.13.0:
10590+
version "0.13.0"
10591+
resolved "https://registry.yarnpkg.com/optimism/-/optimism-0.13.0.tgz#c08904e1439a0eb9e7f86183dafa06cc715ff351"
10592+
integrity sha512-6JAh3dH+YUE4QUdsgUw8nUQyrNeBKfAEKOHMlLkQ168KhIYFIxzPsHakWrRXDnTO+x61RJrS3/2uEt6W0xlocA==
10593+
dependencies:
10594+
"@wry/context" "^0.5.2"
10595+
1057010596
optimize-css-assets-webpack-plugin@^5.0.3:
1057110597
version "5.0.4"
1057210598
resolved "https://registry.yarnpkg.com/optimize-css-assets-webpack-plugin/-/optimize-css-assets-webpack-plugin-5.0.4.tgz#85883c6528aaa02e30bbad9908c92926bb52dc90"
@@ -14245,10 +14271,10 @@ typedoc@0.17.0-3:
1424514271
shelljs "^0.8.3"
1424614272
typedoc-default-themes "0.8.0-0"
1424714273

14248-
typescript@4.0.3:
14249-
version "4.0.3"
14250-
resolved "https://registry.yarnpkg.com/typescript/-/typescript-4.0.3.tgz#153bbd468ef07725c1df9c77e8b453f8d36abba5"
14251-
integrity sha512-tEu6DGxGgRJPb/mVPIZ48e69xCn2yRmCgYmDugAVwmJ6o+0u1RI18eO7E7WBTLYLaEVVOhwQmcdhQHweux/WPg==
14274+
typescript@4.0.5:
14275+
version "4.0.5"
14276+
resolved "https://registry.yarnpkg.com/typescript/-/typescript-4.0.5.tgz#ae9dddfd1069f1cb5beb3ef3b2170dd7c1332389"
14277+
integrity sha512-ywmr/VrTVCmNTJ6iV2LwIrfG1P+lv6luD8sUJs+2eI9NLGigaN+nUQc13iHqisq7bra9lnmUSYqbJvegraBOPQ==
1425214278

1425314279
typescript@^3.0.0:
1425414280
version "3.9.7"

0 commit comments

Comments
 (0)
Please sign in to comment.