Skip to Content
GraphQL Tools

graphql-tools-monorepo / executors/apollo-link/src / ExecutorLink

Class: ExecutorLink

executors/apollo-link/src.ExecutorLink

Hierarchy

  • ApolloLink

    ExecutorLink

Table of contents

Constructors

Properties

Methods

Constructors

constructor

new ExecutorLink(executor): ExecutorLink

Parameters

NameType
executorExecutor

Returns

ExecutorLink

Overrides

apollo.ApolloLink.constructor

Defined in

packages/executors/apollo-link/src/index.ts:52

Properties

getMemoryInternals

Optional getMemoryInternals: () => unknown

Can be provided by a link that has an internal cache to report it’s memory details.

Deprecated

This is an internal API and should not be used directly. This can be removed or changed at any time.

Type declaration

▸ (): unknown

Returns

unknown

Inherited from

apollo.ApolloLink.getMemoryInternals

Defined in

node_modules/@apollo/client/link/core/ApolloLink.d.ts:382


left

Optional Readonly left: ApolloLink

Used to iterate through all links that are concatenations or split links.

Deprecated

This is an internal API and should not be used directly. This can be removed or changed at any time.

Inherited from

apollo.ApolloLink.left

Defined in

node_modules/@apollo/client/link/core/ApolloLink.d.ts:368


Optional Readonly right: ApolloLink

Used to iterate through all links that are concatenations or split links.

Deprecated

This is an internal API and should not be used directly. This can be removed or changed at any time.

Inherited from

apollo.ApolloLink.right

Defined in

node_modules/@apollo/client/link/core/ApolloLink.d.ts:375

Methods

concat

concat(...links): ApolloLink

Combines the link with other links into a single composed link.

Parameters

NameType
...linksApolloLink[]

Returns

ApolloLink

Example

import { ApolloLink, HttpLink } from "@apollo/client"; const previousLink = new ApolloLink((operation, forward) => { // Handle the request return forward(operation); }); const link = previousLink.concat( link1, link2, new HttpLink({ uri: "http://localhost:4000/graphql" }) );

Inherited from

apollo.ApolloLink.concat

Defined in

node_modules/@apollo/client/link/core/ApolloLink.d.ts:351


request

request(operation, forward): Observable<FormattedExecutionResult<Record<string, any>, Record<string, any>>>

Runs the request handler for the provided operation.

[!NOTE] 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.

Parameters

NameType
operationOperation
forwardForwardFunction

Returns

Observable<FormattedExecutionResult<Record<string, any>, Record<string, any>>>

Inherited from

apollo.ApolloLink.request

Defined in

node_modules/@apollo/client/link/core/ApolloLink.d.ts:361


split

split(test, left, right?): ApolloLink

Concatenates a link that conditionally routes a request to different links.

Parameters

NameTypeDescription
test(op: Operation) => booleanA 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.
leftApolloLinkThe link that executes when the test function returns true.
right?ApolloLinkThe 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.

Returns

ApolloLink

Example

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" }) );

Inherited from

apollo.ApolloLink.split

Defined in

node_modules/@apollo/client/link/core/ApolloLink.d.ts:329


concat

concat(...links): ApolloLink

Combines multiple links into a single composed link.

Parameters

NameTypeDescription
...linksApolloLink[]The links to concatenate into a single link. Each link will execute in serial order.

Returns

ApolloLink

Example

const link = ApolloLink.concat(firstLink, secondLink, thirdLink);

Deprecated

Use ApolloLink.from instead. ApolloLink.concat will be removed in a future major version.

Inherited from

apollo.ApolloLink.concat

Defined in

node_modules/@apollo/client/link/core/ApolloLink.d.ts:295


empty

empty(): ApolloLink

Creates a link that completes immediately and does not emit a result.

Returns

ApolloLink

Example

const link = ApolloLink.empty();

Inherited from

apollo.ApolloLink.empty

Defined in

node_modules/@apollo/client/link/core/ApolloLink.d.ts:199


execute

execute(link, request, context): Observable<FormattedExecutionResult<Record<string, any>, Record<string, any>>>

Executes a GraphQL request against a link. The execute function begins the request by calling the request handler of the link.

Parameters

NameTypeDescription
linkApolloLinkThe ApolloLink instance to execute the request.
requestRequestThe GraphQL request details, such as the query and variables.
contextExecuteContextThe execution context for the request, such as the client making the request.

Returns

Observable<FormattedExecutionResult<Record<string, any>, Record<string, any>>>

Example

const observable = ApolloLink.execute(link, { query, variables }, { client }); observable.subscribe({ next(value) { console.log("Received", value); }, error(error) { console.error("Oops got error", error); }, complete() { console.log("Request complete"); }, });

Inherited from

apollo.ApolloLink.execute

Defined in

node_modules/@apollo/client/link/core/ApolloLink.d.ts:279


from

from(links): ApolloLink

Composes multiple links into a single composed link that executes each provided link in serial order.

Parameters

NameTypeDescription
linksApolloLink[]An array of ApolloLink instances or request handlers that are executed in serial order.

Returns

ApolloLink

Example

import { from, HttpLink, ApolloLink } from "@apollo/client"; import { RetryLink } from "@apollo/client/link/retry"; import MyAuthLink from "../auth"; const link = ApolloLink.from([ new RetryLink(), new MyAuthLink(), new HttpLink({ uri: "http://localhost:4000/graphql" }), ]);

Inherited from

apollo.ApolloLink.from

Defined in

node_modules/@apollo/client/link/core/ApolloLink.d.ts:221


split

split(test, left, right?): ApolloLink

Creates a link that conditionally routes a request to different links.

Parameters

NameTypeDescription
test(op: Operation) => booleanA 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.
leftApolloLinkThe link that executes when the test function returns true.
right?ApolloLinkThe 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.

Returns

ApolloLink

Example

import { ApolloLink, HttpLink } from "@apollo/client"; const link = ApolloLink.split( (operation) => operation.getContext().version === 1, new HttpLink({ uri: "http://localhost:4000/v1/graphql" }), new HttpLink({ uri: "http://localhost:4000/v2/graphql" }) );

Inherited from

apollo.ApolloLink.split

Defined in

node_modules/@apollo/client/link/core/ApolloLink.d.ts:248