Registry / api-client / apollo-link-core

apollo-link-core

JSON →
library0.5.4jsnpmunverified

Apollo Link Core (v0.5.4) is the foundational transport layer for Apollo Client's GraphQL communication. It provides a composable, middleware-like link chain architecture for separating network concerns. Currently in maintenance mode as it has been superseded by @apollo/client's built-in link system. Key differentiator: allows customizing fetch behavior, batching, retries, and subscriptions via modular link composition.

npm install apollo-link-core
INSTALL
IMPORT
SIG · APOLLO-LINK-CORE
A
apollo-link-core
api-clientjavascriptv0.5.4
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.

ApolloLink
import { ApolloLink } from 'apollo-link-core'
const ApolloLink = require('apollo-link-core').ApolloLink
Named CommonJS import works correctly, but ESM import is preferred for tree-shaking. ApolloLink is the main class to extend or compose links.
execute
import { execute } from 'apollo-link-core'
const execute = require('apollo-link-core').execute
execute function dispatches a GraphQL operation through the link chain. Named import, not default.
makePromise
import { makePromise } from 'apollo-link-core'
const makePromise = require('apollo-link').makePromise
makePromise converts an Observable to a Promise. Previously incorrectly imported from 'apollo-link' package.

Creates a custom link chain with a logging middleware and an HTTP link, then executes a GraphQL operation using the link.

const { ApolloLink, execute, Observable } = require('apollo-link-core'); const { print } = require('graphql'); const { createHttpLink } = require('apollo-link-http'); const httpLink = createHttpLink({ uri: 'https://api.example.com/graphql' }); const link = ApolloLink.from([ new ApolloLink((operation, forward) => { console.log('Starting request:', operation.operationName); return forward(operation).map(result => { console.log('Received response:', result); return result; }); }), httpLink ]); const operation = { query: print(`{ __typename }`), operationName: 'Test', variables: {} }; execute(link, operation).subscribe({ next: data => console.log(data), error: err => console.error(err) });
Debug
Known issues
deprecatedThis package is in maintenance mode. Use @apollo/client's built-in link system (ApolloLink) for new projects.
fix
Migrate to @apollo/client and import ApolloLink from '@apollo/client'.
affects: >=0.5.0
breakingRemoved 'apollo-link-core/...' submodule imports. All exports are from the main package entry.
fix
Change imports from 'apollo-link-core/something' to 'apollo-link-core'.
affects: >=0.4.0
gotchaexecute returns a ZenObservable, not a Promise. Many developers mistakenly call .then() on it.
fix
Use .subscribe() to consume results, or call makePromise() to convert to a Promise.
affects: >=0.1.0
Errors
Common errors & fixes
TypeError: Cannot read property 'query' of undefined
execute() called with an operation object that is missing the 'query' field.
fix
Ensure the operation object includes a 'query' property (a parsed GraphQL document).
You are calling execute with a link that does not have a function property.
A link in the chain is not a valid ApolloLink instance; it may be an object without 'request' method.
fix
Ensure each link either extends ApolloLink or has a 'request' method returning an Observable.
Upgrade
Version history
0.5.4latest on npm
Audit
Dependencies
graphqlrequiredRequired dependency for GraphQL document parsing and execution.
zen-observable-tsrequiredProvides Observable implementation used by links for subscription support.
apollo-utilitiesrequiredShared utility functions used internally.
Agent activity
52 hits · last 30 days
node
42
OpenAI (training)
1
Resources
apollo-link-core — npm install apollo-link-core · libregistry