Skip to content

Commit

Permalink
Add support for @apollo/client (#15)
Browse files Browse the repository at this point in the history
* Upgrades to apollo/client

* Changes on dependencies

* Update docs

* Drop support before Node v10

* Meet Apollo Client v3 peer deps

Co-authored-by: Maël Nison <nison.mael@gmail.com>
  • Loading branch information
1v4nx and arcanis committed Apr 29, 2021
1 parent 68bb9a7 commit 0735b3f
Show file tree
Hide file tree
Showing 8 changed files with 3,122 additions and 1,995 deletions.
4 changes: 3 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
language: node_js
node_js:
- "6"
- "10"
- "12"
- "14"

script:
- yarn install && yarn test && yarn run coverage && yarn run lint
Expand Down
6 changes: 2 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,8 @@ yarn add apollo-link-debounce
### Usage

```js
import { ApolloLink } from 'apollo-link';
import { HttpLink } from 'apollo-link-http';
import { RetryLink } from 'apollo-link-retry';
import gql from 'graphql-tag';
import { gql, ApolloLink, HttpLink } from '@apollo/client';
import { RetryLink } from '@apollo/client/link/retry';

import DebounceLink from 'apollo-link-debounce';

Expand Down
17 changes: 10 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,22 @@
"name": "apollo-link-debounce",
"version": "2.1.0",
"description": "An Apollo Link to debounce requests",
"dependencies": {
"apollo-link": "^1.2.2",
"zen-observable-ts": "^0.8.9"
"peerDependencies": {
"@apollo/client": "^3.0.0"
},
"devDependencies": {
"@apollo/client": "^3.0.0",
"@types/graphql": "^0.13.0",
"@types/jest": "^23.1.4",
"@types/node": "10.1.2",
"@types/node": "^13.13.2",
"@types/react": "^16.9.34",
"codecov": "^3.0.3",
"graphql": "^0.13.2",
"graphql-tag": "^2.9.2",
"graphql": "^15.0.0",
"nyc": "^11.2.1",
"react": "^17.0.0",
"react-scripts-ts": "^2.16.0",
"tslint": "^5.8.0",
"typescript": "^2.6.2"
"typescript": "^3.8.3"
},
"main": "build/dist/index.js",
"module": "build/dist/index.js",
Expand All @@ -31,12 +32,14 @@
"lint": "tslint src/*.ts* src/**/*.ts*",
"test": "react-scripts-ts test --coverage --collectCoverageFrom=src/**/*.ts* --collectCoverageFrom=!src/index.ts --collectCoverageFrom=!src/TestUtils.ts && yarn run lint",
"testonly": "react-scripts-ts test --env=jsdom",
"prepack": "yarn run build",
"coverage": "codecov -f coverage/*.json"
},
"keywords": [
"graphql",
"apollo",
"apollo-link",
"@apollo/client",
"offline",
"queue"
],
Expand Down
5 changes: 2 additions & 3 deletions src/DebounceLink.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,15 @@ import {
assertObservableSequence,
} from './TestUtils';
import {
gql,
execute,
GraphQLRequest,
ApolloLink,
} from 'apollo-link';
} from '@apollo/client';
import {
ExecutionResult,
} from 'graphql';

import gql from 'graphql-tag';

describe('DebounceLink', () => {
let link: ApolloLink;
let testLink: TestSequenceLink;
Expand Down
7 changes: 4 additions & 3 deletions src/DebounceLink.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import {
ApolloLink,
FetchResult,
Observable,
Observer,
Operation,
NextLink,
} from 'apollo-link';
import { Observable, Observer } from 'zen-observable-ts';
} from '@apollo/client';

interface OperationQueueEntry {
operation: Operation;
Expand Down Expand Up @@ -54,7 +55,7 @@ export default class DebounceLink extends ApolloLink {
if (!debounceKey) {
return forward(operation);
}
return new Observable(observer => {
return new Observable<FetchResult>(observer => {
const debounceGroupId = this.enqueueRequest({ debounceKey, debounceTimeout }, { operation, forward, observer });
return () => {
this.unsubscribe(debounceKey, debounceGroupId, observer);
Expand Down
2 changes: 1 addition & 1 deletion src/TestUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import {
Operation,
Observable,
NextLink,
} from 'apollo-link';
} from '@apollo/client';
import {
ExecutionResult,
} from 'graphql';
Expand Down
3 changes: 2 additions & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
{
"compilerOptions": {
"declaration": true,
"esModuleInterop": true,
"module": "commonjs",
"moduleResolution": "node",
"noImplicitAny": true,
"lib": ["esnext"],
"lib": ["dom", "esnext"],
"removeComments": true,
"preserveConstEnums": true,
"outDir": "build/dist",
Expand Down
Loading

0 comments on commit 0735b3f

Please sign in to comment.