Optional InternalgetCan be provided by a link that has an internal cache to report it's memory details.
Optional Readonly InternalleftUsed to iterate through all links that are concatenations or split links.
Optional Readonly InternalrightUsed to iterate through all links that are concatenations or split links.
Combines the link with other links into a single composed link.
Runs the request handler for the provided operation.
This is called by the ApolloLink.execute function for you and should
not be called directly. Prefer using ApolloLink.execute to make the
request instead.
Concatenates a link that conditionally routes a request to different links.
A predicate function that receives the current operation
and returns a boolean indicating which link to execute. Returning true
executes the left link. Returning false executes the right link.
The link that executes when the test function returns
true.
Optionalright: FlexDataClientLinkThe link that executes when the test function returns
false. If the right link is not provided, the request is forwarded to
the next link in the chain.
import { ApolloLink, HttpLink } from "@apollo/client";
const previousLink = new ApolloLink((operation, forward) => {
// Handle the request
return forward(operation);
});
const link = previousLink.split(
(operation) => operation.getContext().version === 1,
new HttpLink({ uri: "http://localhost:4000/v1/graphql" }),
new HttpLink({ uri: "http://localhost:4000/v2/graphql" })
);
StaticconcatCombines multiple links into a single composed link.
The links to concatenate into a single link. Each link will execute in serial order.
StaticemptyCreates a link that completes immediately and does not emit a result.
StaticexecuteExecutes a GraphQL request against a link. The execute function begins
the request by calling the request handler of the link.
The ApolloLink instance to execute the request.
The GraphQL request details, such as the query and
variables.
The execution context for the request, such as the
client making the request.
StaticfromComposes multiple links into a single composed link that executes each provided link in serial order.
An array of ApolloLink instances or request handlers that
are executed in serial order.
StaticsplitCreates a link that conditionally routes a request to different links.
A predicate function that receives the current operation
and returns a boolean indicating which link to execute. Returning true
executes the left link. Returning false executes the right link.
The link that executes when the test function returns
true.
Optionalright: FlexDataClientLinkThe link that executes when the test function returns
false. If the right link is not provided, the request is forwarded to
the next link in the chain.
Use the
ErrorLinkto perform custom logic when a GraphQL or network error occurs.Remarks
This link is used after the GraphQL operation completes and execution is moving back up your link chain. The
errorHandlerfunction should not return a value unless you want to retry the operation.For more information on the types of errors that might be encountered, see the guide on error handling.
Example