Skip to content

Commit 29323ae

Browse files
update link docs (apollographql#12994)
* update link docs * Update link destination --------- Co-authored-by: Jerel Miller <[email protected]>
1 parent b2da0b8 commit 29323ae

File tree

3 files changed

+15
-47
lines changed

3 files changed

+15
-47
lines changed

docs/source/api/link/introduction.mdx

Lines changed: 11 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -91,50 +91,25 @@ No matter how your chain branches, each branch always ends in a [terminating lin
9191

9292
#### Additive composition
9393

94-
Additive composition composes a link chain by executing links in serial order. You use the [`from`](#from) and [`concat`](#concat) helpers to create a link chain using additive composition.
94+
Additive composition composes a link chain by executing links in serial order. You use the [`ApolloLink.from`](#apollolinkfrom) and [`ApolloLink.concat`](#apollolinkconcat) helpers to create a link chain using additive composition.
9595

96-
##### `from`
96+
##### `ApolloLink.from`
9797

98-
The most common way to compose multiple links together is to use the `from` helper. Pass an array of link objects to `from` to create a composed link that executes each link in serial order:
98+
The most common way to compose multiple links together is to use the static `ApolloLink.from` helper. Pass an array of link objects to `ApolloLink.from` to create a composed link that executes each link in serial order:
9999

100100
```ts
101-
import { from, HttpLink, ApolloLink } from "@apollo/client";
101+
import { HttpLink, ApolloLink } from "@apollo/client";
102102
import { RetryLink } from "@apollo/client/link/retry";
103103
import MyAuthLink from "../auth";
104104

105-
const link = from([
106-
new RetryLink(),
107-
new MyAuthLink(),
108-
new HttpLink({ uri: "http://localhost:4000/graphql" }),
109-
]);
110-
111-
// this also works
112105
const link = ApolloLink.from([
113106
new RetryLink(),
114107
new MyAuthLink(),
115108
new HttpLink({ uri: "http://localhost:4000/graphql" }),
116109
]);
117110
```
118111

119-
##### `concat`
120-
121-
Combine two links together into a single composed link using the `concat` method.
122-
123-
```ts
124-
import { concat, ApolloLink, HttpLink } from "@apollo/client";
125-
import MyAuthLink from "../auth";
126-
127-
const link = concat(
128-
new MyAuthLink(),
129-
new HttpLink({ uri: "http://localhost:4000/graphql" })
130-
);
131-
132-
// this also works
133-
const link = ApolloLink.concat(
134-
new MyAuthLink(),
135-
new HttpLink({ uri: "http://localhost:4000/graphql" })
136-
);
137-
```
112+
##### `ApolloLink.concat`
138113

139114
Each link object includes a `concat` instance method to combine two links into a single composed link. This is useful to combine multiple links together using a chain of function calls:
140115

@@ -156,28 +131,21 @@ The link chain created by the `from` and `concat` examples are functionally equi
156131

157132
#### Directional composition
158133

159-
You might want your link chain's execution to branch, depending on the details of the operation being performed. You use the `split` function to create a link that conditionally routes to different sub-chains.
134+
You might want your link chain's execution to branch, depending on the details of the operation being performed. You use the `ApolloLink.split` method to create a link that conditionally routes to different sub-chains.
160135

161-
The `split` function takes three arguments:
136+
The `ApolloLink.split` function takes three arguments:
162137

163138
| Name | Description |
164139
| ------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
165140
| `test` | A function that takes in the current `operation` and returns `true` or `false`. Returning `true` executes the `left` link. Returning `false` executes the `right` link. |
166141
| `left` | The link passed as the second argument to `split`. This link executes when the `test` function returns `true`. |
167142
| `right` | An optional link passed as the third argument to `split`. This link executes when the `test` function returns `false`. If this is not provided, the request handler's `forward` parameter is used. |
168143

169-
The following example uses `split` to create a link that routes to different `HttpLink` instances depending on the associated context's `version`:
144+
The following example uses `ApolloLink.split` to create a link that routes to different `HttpLink` instances depending on the associated context's `version`:
170145

171146
```ts
172-
import { ApolloLink, HttpLink, split } from "@apollo/client";
173-
174-
const link = split(
175-
(operation) => operation.getContext().version === 1,
176-
new HttpLink({ uri: "http://localhost:4000/v1/graphql" }),
177-
new HttpLink({ uri: "http://localhost:4000/v2/graphql" })
178-
);
147+
import { ApolloLink, HttpLink } from "@apollo/client";
179148

180-
// this also works
181149
const link = ApolloLink.split(
182150
(operation) => operation.getContext().version === 1,
183151
new HttpLink({ uri: "http://localhost:4000/v1/graphql" }),
@@ -214,12 +182,12 @@ Other uses for the `split` method include:
214182
In the following example, all subscription operations are sent to `GraphQLWsLink`, with all other operations sent to `HttpLink`:
215183

216184
```ts
217-
import { split, HttpLink } from "@apollo/client";
185+
import { ApolloLink, HttpLink } from "@apollo/client";
218186
import { GraphQLWsLink } from "@apollo/client/link/subscriptions";
219187
import { OperationTypeNode } from "graphql";
220188
import { createClient } from "graphql-ws";
221189

222-
const link = split(
190+
const link = ApolloLink.split(
223191
({ operationType }) => {
224192
return operationType === OperationTypeNode.SUBSCRIPTION;
225193
},

docs/source/data/subscriptions.mdx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ The following example expands on the previous one by initializing both a `GraphQ
169169

170170
```ts title="index.ts"
171171
import { OperationTypeNode } from "graphql";
172-
import { split, HttpLink } from "@apollo/client";
172+
import { ApolloLink, HttpLink } from "@apollo/client";
173173
import { GraphQLWsLink } from "@apollo/client/link/subscriptions";
174174
import { createClient } from "graphql-ws";
175175

@@ -188,7 +188,7 @@ const wsLink = new GraphQLWsLink(
188188
// * A function that's called for each operation to execute
189189
// * The Link to use for an operation if the function returns a "truthy" value
190190
// * The Link to use for an operation if the function returns a "falsy" value
191-
const splitLink = split(
191+
const splitLink = ApolloLink.split(
192192
({ operationType }) => {
193193
return operationType === OperationTypeNode.SUBSCRIPTION;
194194
},

docs/source/networking/authentication.mdx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ VueJS example:
7272
```js
7373
import ApolloClient from "apollo-client";
7474
import { HttpLink } from "apollo-link-http";
75-
import { ApolloLink, concat } from "apollo-link";
75+
import { ApolloLink } from "apollo-link";
7676
import { InMemoryCache } from "apollo-cache-inmemory";
7777
import { getMainDefinition } from "apollo-utilities";
7878

@@ -89,7 +89,7 @@ const authMiddleware = new ApolloLink((operation, forward) => {
8989
return forward(operation);
9090
});
9191
export const apolloClient = new ApolloClient({
92-
link: concat(authMiddleware, httpLink),
92+
link: authMiddleware.concat(httpLink),
9393
cache: new InMemoryCache(),
9494
});
9595
```

0 commit comments

Comments
 (0)