MCPcopy Index your code
hub / github.com/drcallaway/apollo-link-timeout

github.com/drcallaway/apollo-link-timeout @v5.1.0

Chat with this repo
repository ↗ · DeepWiki ↗ · release v5.1.0 ↗ · + Follow
16 symbols 31 edges 9 files 1 documented · 6% 1 cross-repo links
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

apollo-link-timeout

An Apollo Link that aborts requests that aren't completed within a specified timeout period. Note that timeouts are enforced for query and mutation operations only (not subscriptions).

Installation

npm install apollo-link-timeout

or

yarn add apollo-link-timeout

Usage

import ApolloLinkTimeout from 'apollo-link-timeout';
import { createHttpLink } from 'apollo-link-http';
import { ApolloClient } from 'apollo-client';

...

const timeoutLink = new ApolloLinkTimeout(10000); // 10 second timeout

const httpLink = createHttpLink({ uri: "/graphql" });

const timeoutHttpLink = timeoutLink.concat(httpLink);

const apolloClient = new ApolloClient({ link: timeoutHttpLink });

// use timeout-enabled Apollo client...

// Override timeout from any query
<Query
 query={SOME_QUERY}
 variables={{
    someVar1: "foo",
    someVar2: "bar",
   }}
  context={{ timeout: 3000 }}
>
// ...

API

new ApolloLinkTimeout(timeout?, statusCode?)

Creates a new TimeoutLink instance that aborts requests if the timeout expires before the response is received.

Parameters:

  • timeout (optional): The timeout in milliseconds for the request. Defaults to 15000ms (15 seconds) if omitted.
  • statusCode (optional): The HTTP status code to return when a timeout occurs. Defaults to 408 (Request Timeout) if omitted.

Overriding Timeout Per Operation

You can override the default timeout for individual operations by setting a timeout value in the operation context:

// Override timeout in a query
<Query
  query={SOME_QUERY}
  variables={{
    someVar1: "foo",
    someVar2: "bar",
  }}
  context={{ timeout: 3000 }} // 3 second timeout for this query
>
  // ...
</Query>


// Or when calling the client directly
apolloClient.query({
  query: SOME_QUERY,
  context: { timeout: 5000 } // 5 second timeout
});

// Or via a prior link
const link = new ApolloLink((operation, forward) => {
  operation.setContext({ timeout: 5000 });
});
link.concat(timeoutLink);

The timeout resolution follows this priority: operation-level context timeout > link-level timeout > default (15000ms).

Disabling Timeout

To disable the timeout for a specific operation, set the timeout to a negative value in the operation context:

apolloClient.query({
  query: SOME_QUERY,
  context: { timeout: -1 } // Disable timeout for this query
});

When a negative timeout is provided, the timeout link will be skipped and the operation will proceed without any timeout enforcement.

See Apollo documentation for information on using the Apollo client.

Core symbols most depended-on inside this repo

constructor
called by 0
src/TimeoutError.ts
constructor
called by 0
src/timeoutLink.ts
request
called by 0
src/timeoutLink.ts
cancelTimeout
called by 0
src/timeoutLink.ts

Shape

Class 6
Function 5
Method 5

Languages

TypeScript100%

Modules by API surface

src/timeoutLink.ts5 symbols
__tests__/timeoutLink.test.ts4 symbols
src/TimeoutError.ts3 symbols
__tests__/fixedEnvironment.js3 symbols
__tests__/integration/run.mjs1 symbols

Used by 1 indexed graphs manifest dependencies, hub-wide

For agents

$ claude mcp add apollo-link-timeout \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact