@twilio/flex-sdk
    Preparing search index...

    Class ErrorLink

    Use the ErrorLink to perform custom logic when a GraphQL or network error occurs.

    This link is used after the GraphQL operation completes and execution is moving back up your link chain. The errorHandler function 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.

    import { ErrorLink } from "@apollo/client/link/error";
    import {
    CombinedGraphQLErrors,
    CombinedProtocolErrors,
    } from "@apollo/client/errors";

    // Log any GraphQL errors, protocol errors, or network error that occurred
    const errorLink = new ErrorLink(({ error, operation }) => {
    if (CombinedGraphQLErrors.is(error)) {
    error.errors.forEach(({ message, locations, path }) =>
    console.log(
    `[GraphQL error]: Message: ${message}, Location: ${locations}, Path: ${path}`
    )
    );
    } else if (CombinedProtocolErrors.is(error)) {
    error.errors.forEach(({ message, extensions }) =>
    console.log(
    `[Protocol error]: Message: ${message}, Extensions: ${JSON.stringify(
    extensions
    )}`
    )
    );
    } else {
    console.error(`[Network error]: ${error}`);
    }
    });

    Hierarchy (View Summary)

    Index

    Constructors

    Properties

    getMemoryInternals?: () => unknown

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

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

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

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

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

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

    Methods

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

      Parameters

      Returns FlexDataClientLink

      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" })
      );
    • Concatenates a link that conditionally routes a request to different links.

      Parameters

      • test: (op: Operation) => boolean

        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.

      • left: FlexDataClientLink

        The link that executes when the test function returns true.

      • Optionalright: FlexDataClientLink

        The 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 FlexDataClientLink

      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" })
      );
    • Combines multiple links into a single composed link.

      Parameters

      • ...links: FlexDataClientLink[]

        The links to concatenate into a single link. Each link will execute in serial order.

      Returns FlexDataClientLink

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

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

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

      Parameters

      • link: FlexDataClientLink

        The ApolloLink instance to execute the request.

      • request: Request

        The GraphQL request details, such as the query and variables.

      • context: ExecuteContext

        The execution context for the request, such as the client making the request.

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

      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");
      },
      });
    • Composes multiple links into a single composed link that executes each provided link in serial order.

      Parameters

      • links: FlexDataClientLink[]

        An array of ApolloLink instances or request handlers that are executed in serial order.

      Returns FlexDataClientLink

      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" }),
      ]);
    • Creates a link that conditionally routes a request to different links.

      Parameters

      • test: (op: Operation) => boolean

        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.

      • left: FlexDataClientLink

        The link that executes when the test function returns true.

      • Optionalright: FlexDataClientLink

        The 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 FlexDataClientLink

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