1 | ---
|
2 | title: apollo-link-dedup
|
3 | description: Deduplicate matching requests before making a request
|
4 | ---
|
5 |
|
6 | *NOTE* This link is included by default when using apollo-client so you don't need to add it to your link chain if using apollo-client.
|
7 |
|
8 | ## Installation
|
9 |
|
10 | `npm install apollo-link-dedup --save`
|
11 |
|
12 | ## Usage
|
13 | ```js
|
14 | import { DedupLink } from "apollo-link-dedup";
|
15 |
|
16 | const link = new DedupLink();
|
17 | ```
|
18 |
|
19 | ## Options
|
20 | The Dedup Link does not take any options when creating the link.
|
21 |
|
22 | ## Context
|
23 | The Dedup Link can be overridden by using the context on a per operation basis:
|
24 | - `forceFetch`: a true or false (defaults to false) to bypass deduplication per request
|
25 |
|
26 | ```js
|
27 | import { createHttpLink } from "apollo-link-http";
|
28 | import ApolloClient from "apollo-client";
|
29 | import InMemoryCache from "apollo-cache-inmemory";
|
30 |
|
31 | const client = new ApolloClient({
|
32 | link: createHttpLink({ uri: "/graphql" }),
|
33 | cache: new InMemoryCache()
|
34 | });
|
35 |
|
36 | // a query with apollo-client that will not be deduped
|
37 | client.query({
|
38 | query: MY_QUERY,
|
39 | context: {
|
40 | forceFetch: true
|
41 | }
|
42 | })
|
43 | ```
|