From 2b6c813ec6a4fe795b61ab1979cf87e511fd70f4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Arda=20Tanr=C4=B1kulu?= <20847995+ardatan@users.noreply.github.com> Date: Tue, 27 Oct 2020 04:46:31 +0300 Subject: [PATCH] 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 --- .changeset/new-pears-compete.md | 8 +++++ .changeset/thin-ways-wave.md | 5 +++ .github/workflows/canary.yml | 8 ++--- .github/workflows/release.yml | 8 ++--- .github/workflows/tests.yml | 14 ++++---- .github/workflows/website.yml | 8 ++--- package.json | 2 +- packages/links/package.json | 14 +++++--- packages/links/src/AwaitVariablesLink.ts | 3 +- packages/links/src/createServerHttpLink.ts | 2 +- packages/links/src/linkToExecutor.ts | 4 ++- packages/links/src/linkToSubscriber.ts | 3 +- packages/loaders/url/src/index.ts | 2 +- .../utils/src/observableToAsyncIterable.ts | 31 ++++++++-------- packages/wrap/src/transforms/HoistField.ts | 4 +-- yarn.lock | 36 ++++++++++++++++--- 16 files changed, 99 insertions(+), 53 deletions(-) create mode 100644 .changeset/new-pears-compete.md create mode 100644 .changeset/thin-ways-wave.md diff --git a/.changeset/new-pears-compete.md b/.changeset/new-pears-compete.md new file mode 100644 index 00000000000..8e179a55b35 --- /dev/null +++ b/.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) diff --git a/.changeset/thin-ways-wave.md b/.changeset/thin-ways-wave.md new file mode 100644 index 00000000000..53b97fb4ada --- /dev/null +++ b/.changeset/thin-ways-wave.md @@ -0,0 +1,5 @@ +--- +'@graphql-tools/utils': patch +--- + +fix(utils): fix typing mismatch between linkToSubscriber and observableToAsyncIterable diff --git a/.github/workflows/canary.yml b/.github/workflows/canary.yml index ad7bea90036..c500a1656eb 100644 --- a/.github/workflows/canary.yml +++ b/.github/workflows/canary.yml @@ -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" @@ -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' diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 5451ef0d28a..33fedb275b8 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -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: @@ -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 diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index a97333b060d..3cfff51cf36 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -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)" @@ -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: @@ -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)" @@ -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: @@ -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 @@ -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: diff --git a/.github/workflows/website.yml b/.github/workflows/website.yml index 89ba452073a..0836caa36e0 100644 --- a/.github/workflows/website.yml +++ b/.github/workflows/website.yml @@ -27,7 +27,7 @@ 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)" @@ -35,11 +35,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: Deploy 🚀 run: yarn deploy:website env: diff --git a/package.json b/package.json index fe6c87dbe79..b30e6241e4e 100644 --- a/package.json +++ b/package.json @@ -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": { diff --git a/packages/links/package.json b/packages/links/package.json index 805b8d1bc72..5e242c8a036 100644 --- a/packages/links/package.json +++ b/packages/links/package.json @@ -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", diff --git a/packages/links/src/AwaitVariablesLink.ts b/packages/links/src/AwaitVariablesLink.ts index 1f4773e33b9..ee9595e9eda 100644 --- a/packages/links/src/AwaitVariablesLink.ts +++ b/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 { return Promise.resolve(object).then(resolvedObject => { diff --git a/packages/links/src/createServerHttpLink.ts b/packages/links/src/createServerHttpLink.ts index a1718773ce5..3669808b7fc 100644 --- a/packages/links/src/createServerHttpLink.ts +++ b/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'; diff --git a/packages/links/src/linkToExecutor.ts b/packages/links/src/linkToExecutor.ts index c5aa5cd170b..12bf7bb61ee 100644 --- a/packages/links/src/linkToExecutor.ts +++ b/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) => ({ diff --git a/packages/links/src/linkToSubscriber.ts b/packages/links/src/linkToSubscriber.ts index 14836c3abed..b740f29c73b 100644 --- a/packages/links/src/linkToSubscriber.ts +++ b/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'; diff --git a/packages/loaders/url/src/index.ts b/packages/loaders/url/src/index.ts index fe1d9a6c6eb..e3602858a92 100644 --- a/packages/loaders/url/src/index.ts +++ b/packages/loaders/url/src/index.ts @@ -148,7 +148,7 @@ export class UrlLoader implements DocumentLoader { query: document, variables, }) - ) as AsyncIterator>; + ) as AsyncIterableIterator>; }; } diff --git a/packages/utils/src/observableToAsyncIterable.ts b/packages/utils/src/observableToAsyncIterable.ts index 6bbf602fe70..5407bc55f31 100644 --- a/packages/utils/src/observableToAsyncIterable.ts +++ b/packages/utils/src/observableToAsyncIterable.ts @@ -14,11 +14,7 @@ export interface Observable { export type Callback = (value?: any) => any; -export function observableToAsyncIterable( - observable: Observable -): AsyncIterator & { - [Symbol.asyncIterator]: () => AsyncIterator; -} { +export function observableToAsyncIterable(observable: Observable): AsyncIterable { const pullQueue: Array = []; const pushQueue: Array = []; @@ -74,19 +70,20 @@ export function observableToAsyncIterable( }; 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); + }, + }; }, }; } diff --git a/packages/wrap/src/transforms/HoistField.ts b/packages/wrap/src/transforms/HoistField.ts index 198aa0aa2f1..d58bc034499 100644 --- a/packages/wrap/src/transforms/HoistField.ts +++ b/packages/wrap/src/transforms/HoistField.ts @@ -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; diff --git a/yarn.lock b/yarn.lock index 3c7ccf693ba..83ce4962a40 100644 --- a/yarn.lock +++ b/yarn.lock @@ -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" @@ -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== @@ -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" @@ -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"