Skip to content

Commit

Permalink
Update links package to use @apollo/client/links (#2138)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
ardatan committed Oct 27, 2020
1 parent e2b1eac commit 2b6c813
Show file tree
Hide file tree
Showing 16 changed files with 99 additions and 53 deletions.
8 changes: 8 additions & 0 deletions .changeset/new-pears-compete.md
@@ -0,0 +1,8 @@
---
'@graphql-tools/links': major
---

feat(links): AC3 support

`apollo-link` has been deprecated so this package now uses `@apollo/client` as peer dependency;
You can [see more on migration guide.](https://www.apollographql.com/docs/react/migrating/apollo-client-3-migration/#apollo-link-and-apollo-link-http)
5 changes: 5 additions & 0 deletions .changeset/thin-ways-wave.md
@@ -0,0 +1,5 @@
---
'@graphql-tools/utils': patch
---

fix(utils): fix typing mismatch between linkToSubscriber and observableToAsyncIterable
8 changes: 4 additions & 4 deletions .github/workflows/canary.yml
Expand Up @@ -16,7 +16,7 @@ jobs:
- name: Use Node
uses: actions/setup-node@v1
with:
node-version: '14.x'
node-version: '15.x'
- name: Configure Git Credentials
run: |
git config --global user.email "theguild-bot@users.noreply.github.com"
Expand All @@ -33,11 +33,11 @@ jobs:
uses: actions/cache@v1
with:
path: ${{ steps.yarn-cache.outputs.dir }}
key: ${{ runner.os }}-14-15-yarn-${{ hashFiles('yarn.lock') }}
key: ${{ runner.os }}-15-15-yarn-${{ hashFiles('yarn.lock') }}
restore-keys: |
${{ runner.os }}-14-15-yarn-
${{ runner.os }}-15-15-yarn-
- name: Install Dependencies using Yarn
run: yarn install && git checkout yarn.lock
run: yarn install --ignore-engines && git checkout yarn.lock
- name: Release Canary
id: canary
uses: 'kamilkisiela/release-canary@master'
Expand Down
8 changes: 4 additions & 4 deletions .github/workflows/release.yml
Expand Up @@ -24,7 +24,7 @@ jobs:
- name: Use Node
uses: actions/setup-node@v1
with:
node-version: '14.x'
node-version: '15.x'
- name: Setup NPM credentials
run: echo "//registry.npmjs.org/:_authToken=$NODE_AUTH_TOKEN" >> ~/.npmrc
env:
Expand All @@ -36,11 +36,11 @@ jobs:
uses: actions/cache@v1
with:
path: ${{ steps.yarn-cache.outputs.dir }}
key: ${{ runner.os }}-14-15-yarn-${{ hashFiles('yarn.lock') }}
key: ${{ runner.os }}-15-15-yarn-${{ hashFiles('yarn.lock') }}
restore-keys: |
${{ runner.os }}-14-15-yarn-
${{ runner.os }}-15-15-yarn-
- name: Install Dependencies using Yarn
run: yarn install && git checkout yarn.lock
run: yarn install --ignore-engines && git checkout yarn.lock
- name: Build
run: yarn build
- name: Create Release Pull Request or Publish to npm
Expand Down
14 changes: 7 additions & 7 deletions .github/workflows/tests.yml
Expand Up @@ -15,10 +15,10 @@ jobs:
steps:
- name: Checkout Master
uses: actions/checkout@v1
- name: Use Node 14
- name: Use Node 15
uses: actions/setup-node@master
with:
node-version: 14
node-version: 15
- name: Get yarn cache
id: yarn-cache
run: echo "::set-output name=dir::$(yarn cache dir)"
Expand All @@ -30,7 +30,7 @@ jobs:
restore-keys: |
${{ runner.os }}-${{matrix.node_version}}-${{matrix.graphql_version}}-yarn
- name: Install Dependencies using Yarn
run: yarn install && git checkout yarn.lock
run: yarn install --ignore-engines && git checkout yarn.lock
- name: Lint
run: yarn lint
build:
Expand All @@ -45,7 +45,7 @@ jobs:
- name: Use Node 14
uses: actions/setup-node@master
with:
node-version: 14
node-version: 15
- name: Get yarn cache
id: yarn-cache
run: echo "::set-output name=dir::$(yarn cache dir)"
Expand All @@ -59,7 +59,7 @@ jobs:
- name: Use GraphQL v${{matrix.graphql_version}}
run: node ./scripts/match-graphql.js ${{matrix.graphql_version}}
- name: Install Dependencies using Yarn
run: yarn install && git checkout yarn.lock
run: yarn install --ignore-engines && git checkout yarn.lock
- name: Build
run: yarn ts:transpile
test:
Expand All @@ -68,7 +68,7 @@ jobs:
strategy:
matrix:
os: [ubuntu-latest, windows-latest]
node_version: [10, 14]
node_version: [10, 15]
graphql_version: [14, 15]
steps:
- name: Checkout Master
Expand All @@ -90,7 +90,7 @@ jobs:
- name: Use GraphQL v${{matrix.graphql_version}}
run: node ./scripts/match-graphql.js ${{matrix.graphql_version}}
- name: Install Dependencies using Yarn
run: yarn install && git checkout yarn.lock
run: yarn install --ignore-engines && git checkout yarn.lock
- name: Cache Jest
uses: actions/cache@v1
with:
Expand Down
8 changes: 4 additions & 4 deletions .github/workflows/website.yml
Expand Up @@ -27,19 +27,19 @@ jobs:
- name: Use Node
uses: actions/setup-node@v1
with:
node-version: '14.x'
node-version: '15.x'
- name: Get yarn cache
id: yarn-cache
run: echo "::set-output name=dir::$(yarn cache dir)"
- name: Cache Yarn
uses: actions/cache@v1
with:
path: ${{ steps.yarn-cache.outputs.dir }}
key: ${{ runner.os }}-14-15-yarn-${{ hashFiles('yarn.lock') }}
key: ${{ runner.os }}-15-15-yarn-${{ hashFiles('yarn.lock') }}
restore-keys: |
${{ runner.os }}-14-15-yarn-
${{ runner.os }}-15-15-yarn-
- name: Install Dependencies using Yarn
run: yarn install && git checkout yarn.lock
run: yarn install --ignore-engines && git checkout yarn.lock
- name: Deploy 🚀
run: yarn deploy:website
env:
Expand Down
2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -67,7 +67,7 @@
"ts-jest": "26.4.1",
"typedoc": "0.17.0-3",
"typedoc-plugin-markdown": "2.3.1",
"typescript": "4.0.3"
"typescript": "4.0.5"
},
"husky": {
"hooks": {
Expand Down
14 changes: 10 additions & 4 deletions packages/links/package.json
Expand Up @@ -12,19 +12,25 @@
"definition": "dist/index.d.ts"
},
"peerDependencies": {
"graphql": "^14.0.0 || ^15.0.0"
"graphql": "^14.0.0 || ^15.0.0",
"@apollo/client": "~3.2.5"
},
"buildOptions": {
"input": "./src/index.ts"
"input": "./src/index.ts",
"external": [
"@apollo/client/link/core",
"@apollo/client/link/utils",
"@apollo/client/utilities"
]
},
"devDependencies": {
"@apollo/client": "3.2.5",
"@types/graphql-upload": "8.0.4",
"express-graphql": "0.11.0",
"graphql-upload": "11.0.0"
},
"dependencies": {
"@graphql-tools/utils": "^7.0.0",
"apollo-link": "1.2.14",
"@graphql-tools/utils": "7.0.0",
"apollo-upload-client": "14.1.2",
"cross-fetch": "3.0.6",
"form-data": "3.0.0",
Expand Down
3 changes: 2 additions & 1 deletion packages/links/src/AwaitVariablesLink.ts
@@ -1,4 +1,5 @@
import { ApolloLink, Operation, NextLink, Observable, FetchResult } from 'apollo-link';
import { ApolloLink, FetchResult, NextLink, Operation } from '@apollo/client/link/core';
import { Observable } from '@apollo/client/utilities';

function getFinalPromise(object: any): Promise<any> {
return Promise.resolve(object).then(resolvedObject => {
Expand Down
2 changes: 1 addition & 1 deletion packages/links/src/createServerHttpLink.ts
@@ -1,4 +1,4 @@
import { concat } from 'apollo-link';
import { concat } from '@apollo/client/link/core';
import { createUploadLink, formDataAppendFile, isExtractableFile } from 'apollo-upload-client';
import FormData, { AppendOptions } from 'form-data';
import { fetch } from 'cross-fetch';
Expand Down
4 changes: 3 additions & 1 deletion packages/links/src/linkToExecutor.ts
@@ -1,4 +1,6 @@
import { ApolloLink, toPromise, execute, Observable, FetchResult } from 'apollo-link';
import { ApolloLink, execute, FetchResult } from '@apollo/client/link/core';
import { Observable } from '@apollo/client/utilities';
import { toPromise } from '@apollo/client/link/utils';
import { DocumentNode, GraphQLResolveInfo } from 'graphql';

export const linkToExecutor = (link: ApolloLink) => <TReturn, TArgs, TContext>({
Expand Down
3 changes: 2 additions & 1 deletion packages/links/src/linkToSubscriber.ts
@@ -1,4 +1,5 @@
import { ApolloLink, execute, FetchResult, Observable } from 'apollo-link';
import { ApolloLink, execute, FetchResult } from '@apollo/client/link/core';
import { Observable } from '@apollo/client/utilities';
import { observableToAsyncIterable } from '@graphql-tools/utils';
import { GraphQLResolveInfo, DocumentNode } from 'graphql';

Expand Down
2 changes: 1 addition & 1 deletion packages/loaders/url/src/index.ts
Expand Up @@ -148,7 +148,7 @@ export class UrlLoader implements DocumentLoader<LoadFromUrlOptions> {
query: document,
variables,
})
) as AsyncIterator<ExecutionResult<TReturn>>;
) as AsyncIterableIterator<ExecutionResult<TReturn>>;
};
}

Expand Down
31 changes: 14 additions & 17 deletions packages/utils/src/observableToAsyncIterable.ts
Expand Up @@ -14,11 +14,7 @@ export interface Observable<T> {

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

export function observableToAsyncIterable<T>(
observable: Observable<T>
): AsyncIterator<T> & {
[Symbol.asyncIterator]: () => AsyncIterator<T>;
} {
export function observableToAsyncIterable<T>(observable: Observable<T>): AsyncIterable<T> {
const pullQueue: Array<Callback> = [];
const pushQueue: Array<any> = [];

Expand Down Expand Up @@ -74,19 +70,20 @@ export function observableToAsyncIterable<T>(
};

return {
next() {
return listening ? pullValue() : this.return();
},
return() {
emptyQueue();
return Promise.resolve({ value: undefined, done: true });
},
throw(error) {
emptyQueue();
return Promise.reject(error);
},
[Symbol.asyncIterator]() {
return this;
return {
next() {
return listening ? pullValue() : this.return();
},
return() {
emptyQueue();
return Promise.resolve({ value: undefined, done: true });
},
throw(error) {
emptyQueue();
return Promise.reject(error);
},
};
},
};
}
4 changes: 2 additions & 2 deletions packages/wrap/src/transforms/HoistField.ts
Expand Up @@ -119,14 +119,14 @@ export default class HoistField implements Transform {

Object.keys(targetField.args).forEach(argName => {
const argConfig = targetField.args[argName];
const arg: GraphQLArgument = {
const arg = {
...argConfig,
name: argName,
description: argConfig.description,
defaultValue: argConfig.defaultValue,
extensions: argConfig.extensions,
astNode: argConfig.astNode,
};
} as GraphQLArgument;
if (this.argFilters[level](arg)) {
argsMap[argName] = arg;
this.argLevels[arg.name] = level;
Expand Down
36 changes: 31 additions & 5 deletions yarn.lock
Expand Up @@ -106,6 +106,25 @@
"@algolia/logger-common" "4.5.1"
"@algolia/requester-common" "4.5.1"

"@apollo/client@3.2.5":
version "3.2.5"
resolved "https://registry.yarnpkg.com/@apollo/client/-/client-3.2.5.tgz#24e0a6faa1d231ab44807af237c6227410c75c4d"
integrity sha512-zpruxnFMz6K94gs2pqc3sidzFDbQpKT5D6P/J/I9s8ekHZ5eczgnRp6pqXC86Bh7+44j/btpmOT0kwiboyqTnA==
dependencies:
"@graphql-typed-document-node/core" "^3.0.0"
"@types/zen-observable" "^0.8.0"
"@wry/context" "^0.5.2"
"@wry/equality" "^0.2.0"
fast-json-stable-stringify "^2.0.0"
graphql-tag "^2.11.0"
hoist-non-react-statics "^3.3.2"
optimism "^0.13.0"
prop-types "^15.7.2"
symbol-observable "^2.0.0"
ts-invariant "^0.4.4"
tslib "^1.10.0"
zen-observable "^0.8.14"

"@apollo/client@^3.1.5":
version "3.2.2"
resolved "https://registry.yarnpkg.com/@apollo/client/-/client-3.2.2.tgz#fe5cad4d53373979f13a925e9da02d8743e798a5"
Expand Down Expand Up @@ -3357,7 +3376,7 @@ apollo-graphql@^0.6.0:
apollo-env "^0.6.5"
lodash.sortby "^4.7.0"

apollo-link@1.2.14, apollo-link@^1.2.14:
apollo-link@^1.2.14:
version "1.2.14"
resolved "https://registry.yarnpkg.com/apollo-link/-/apollo-link-1.2.14.tgz#3feda4b47f9ebba7f4160bef8b977ba725b684d9"
integrity sha512-p67CMEFP7kOG1JZ0ZkYZwRDa369w5PIjtMjvrQd/HnIV8FRsHRqLqK+oAZQnFa1DDdZtOtHTi+aMIW6EatC2jg==
Expand Down Expand Up @@ -10567,6 +10586,13 @@ optimism@^0.12.1:
dependencies:
"@wry/context" "^0.5.2"

optimism@^0.13.0:
version "0.13.0"
resolved "https://registry.yarnpkg.com/optimism/-/optimism-0.13.0.tgz#c08904e1439a0eb9e7f86183dafa06cc715ff351"
integrity sha512-6JAh3dH+YUE4QUdsgUw8nUQyrNeBKfAEKOHMlLkQ168KhIYFIxzPsHakWrRXDnTO+x61RJrS3/2uEt6W0xlocA==
dependencies:
"@wry/context" "^0.5.2"

optimize-css-assets-webpack-plugin@^5.0.3:
version "5.0.4"
resolved "https://registry.yarnpkg.com/optimize-css-assets-webpack-plugin/-/optimize-css-assets-webpack-plugin-5.0.4.tgz#85883c6528aaa02e30bbad9908c92926bb52dc90"
Expand Down Expand Up @@ -14245,10 +14271,10 @@ typedoc@0.17.0-3:
shelljs "^0.8.3"
typedoc-default-themes "0.8.0-0"

typescript@4.0.3:
version "4.0.3"
resolved "https://registry.yarnpkg.com/typescript/-/typescript-4.0.3.tgz#153bbd468ef07725c1df9c77e8b453f8d36abba5"
integrity sha512-tEu6DGxGgRJPb/mVPIZ48e69xCn2yRmCgYmDugAVwmJ6o+0u1RI18eO7E7WBTLYLaEVVOhwQmcdhQHweux/WPg==
typescript@4.0.5:
version "4.0.5"
resolved "https://registry.yarnpkg.com/typescript/-/typescript-4.0.5.tgz#ae9dddfd1069f1cb5beb3ef3b2170dd7c1332389"
integrity sha512-ywmr/VrTVCmNTJ6iV2LwIrfG1P+lv6luD8sUJs+2eI9NLGigaN+nUQc13iHqisq7bra9lnmUSYqbJvegraBOPQ==

typescript@^3.0.0:
version "3.9.7"
Expand Down

0 comments on commit 2b6c813

Please sign in to comment.