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)
});
Errors
Common errors & fixes
TypeError: Cannot read property 'query' of undefined
execute() called with an operation object that is missing the 'query' field.
fixEnsure 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.
fixEnsure each link either extends ApolloLink or has a 'request' method returning an Observable.
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.