# apollo-link-timeout

> Abort requests that take longer than a specified timeout period

Latest version **5.1.0** (published 2025-12-31) · MIT license · 0 weekly downloads

## Install

```sh
npm install apollo-link-timeout
pnpm add apollo-link-timeout
yarn add apollo-link-timeout
bun add apollo-link-timeout
```

## Health

**Score 70/100 (B)** — status: stable.

Positive: has types; esm support; no vulnerabilities; has provenance; high maintenance score; high quality score.

Warnings: low downloads.

## Facts

| | |
|---|---|
| Version | 5.1.0 |
| Published | 2025-12-31 |
| First published | 2018-06-20 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 0 |
| Unpacked size | 28.6 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Provenance | attested (GitHub Actions) |
| GitHub stars | 75 |
| Author | Dustin Callaway |
| Maintainers | masterodin, drcallaway |
| Keywords | graphql, apollo, apollo-link, timeout |

## Links

- npm: https://www.npmjs.com/package/apollo-link-timeout
- Repository: https://github.com/drcallaway/apollo-link-timeout
- Homepage: https://github.com/drcallaway/apollo-link-timeout#readme
- Issues: https://github.com/drcallaway/apollo-link-timeout/issues
- npm.io page: https://npm.io/package/apollo-link-timeout

## Alternatives

- [apollo-link-http-common](https://npm.io/package/apollo-link-http-common.md) — 879.0K weekly downloads
- [react-relay](https://npm.io/package/react-relay.md) — 336.8K weekly downloads
- [relay-test-utils](https://npm.io/package/relay-test-utils.md) — 181.6K weekly downloads
- [@vendure/core](https://npm.io/package/@vendure/core.md) — 14.8K weekly downloads
- [@pnpm/deps.graph-sequencer](https://npm.io/package/@pnpm/deps.graph-sequencer.md) — 13.4K weekly downloads

## Recent versions

- 5.1.0 (latest) — 2025-12-31
- 5.0.4 — 2025-11-30
- 5.0.3 — 2025-11-30
- 5.0.2 — 2025-03-30
- 5.0.1 — 2025-03-30
- 5.0.0 — 2025-02-13
- 4.0.0 — 2021-01-05
- 3.0.0 — 2020-10-20
- 2.0.1 — 2020-08-17
- 1.4.1 — 2020-06-10
- 1.4.0 — 2019-12-06
- 1.3.1 — 2019-06-14
- 1.3.0 — 2019-06-10
- 1.2.1 — 2019-01-25
- 1.2.0 — 2019-01-25
- … 13 more at https://npm.io/package/apollo-link-timeout/versions

## README

# apollo-link-timeout

An [Apollo Link](https://www.apollographql.com/docs/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

```bash
npm install apollo-link-timeout
```

or

```bash
yarn add apollo-link-timeout
```

## Usage

```javascript
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:

```javascript
// 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:

```javascript
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](https://www.apollographql.com/client) for information on using the Apollo client.

---
_Source: https://npm.io/package/apollo-link-timeout · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
