Registry / testing / apollo-link-error

apollo-link-error

JSON →
library1.1.13jsnpmunverified

An Apollo Link for handling and inspecting GraphQL and network errors. Current stable version is 1.1.13, part of the Apollo Link ecosystem (now legacy, superseded by Apollo Client 3's @apollo/client links). Provides a callback-based API to log, retry, or modify operations on error. Key differentiator: integrates directly with Apollo Client's link chain, supporting both graphQLErrors and networkError distinctions, with ability to retry via forward().

npm install apollo-link-error
INSTALL
IMPORT
SIG · APOLLO-LINK-ERROR
A
apollo-link-error
testingjavascriptv1.1.13
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

onError
import { onError } from 'apollo-link-error'
import onError from 'apollo-link-error'
Named export, not default export. CommonJS: const { onError } = require('apollo-link-error').
ErrorLink
import { ErrorLink } from 'apollo-link-error'
const ErrorLink = require('apollo-link-error').ErrorLink
Named export for the class itself (less commonly used). Available in both TypeScript and JavaScript.
ErrorResponse
import type { ErrorResponse } from 'apollo-link-error'
import { ErrorResponse } from 'apollo-link-error'
TypeScript-only type import. Not a runtime value; use with `import type` to avoid runtime inclusion.

Creates an error link that logs GraphQL and network errors, then attaches it to Apollo Client via from().

import { onError } from 'apollo-link-error'; import { ApolloClient, InMemoryCache, from } from '@apollo/client'; const errorLink = onError(({ graphQLErrors, networkError }) => { if (graphQLErrors) { graphQLErrors.forEach(({ message, locations, path }) => console.log(`[GraphQL error]: Message: ${message}, Location: ${locations}, Path: ${path}`) ); } if (networkError) console.log(`[Network error]: ${networkError}`); }); const client = new ApolloClient({ link: from([errorLink]), // combine with other links cache: new InMemoryCache(), });
Debug
Known issues
deprecatedapollo-link-error is deprecated in favor of @apollo/client link utilities since Apollo Client 3.0.
fix
Use import { onError } from '@apollo/client/link/error' with Apollo Client >=3.
affects: >=3.0.0 <4
breakingIn apollo-link-error 1.0.x, the onError callback did not receive 'forward'. It was added in 1.1.0.
fix
Upgrade to 1.1.0+ or use forward if retrying; for older versions, retrying requires manual observable creation.
affects: <1.1.0
gotchaCalling forward(operation) inside onError does not pass new errors from the retried request back into the same error link to avoid infinite loops.
fix
Handle errors from retried requests in a downstream link or fallback logic.
affects: >=1.1.0
gotchaThe 'graphQLErrors' field may be empty if the server returns an HTTP error; in that case, check 'networkError.result.errors'.
fix
Check both graphQLErrors and networkError?.result?.errors for complete error coverage.
affects: >=1.0.0
deprecatedApollo Link ecosystem (including apollo-link-error) is in maintenance mode; no new features planned.
fix
Migrate to Apollo Client >=3 which includes integrated links.
affects: all
Errors
Common errors & fixes
Cannot find module 'apollo-link-error'
apollo-link-error is not installed or incorrectly imported after legacy removal.
fix
npm install apollo-link-error or use @apollo/client's equivalent: npm install @apollo/client
TypeError: onError is not a function
Default import used instead of named import.
fix
Change to: import { onError } from 'apollo-link-error'
Property 'forward' does not exist on type '{ ... }'
Using an older version (<1.1.0) that doesn't include forward in callback.
fix
Upgrade to apollo-link-error@^1.1.0 or check type definitions match installed version.
Cannot read property 'errors' of undefined
networkError.result is undefined when not an HTTP error.
fix
Check if networkError?.result?.errors exists before accessing it.
Upgrade
Version history
1.1.13latest on npm
Audit
Dependencies
apollo-linkrequiredCore link interface; apollo-link-error is designed to be used in an Apollo Link chain.
graphqlrequiredTypeScript types and GraphQL operation objects are from the graphql package.
Agent activity
40 hits · last 30 days
node
32
OpenAI (training)
3
Resources
apollo-link-error — npm install apollo-link-error · libregistry