Registry / api / apollo-link-rest

apollo-link-rest

JSON →
library0.10.0-rc.2jsnpmunverified

Apollo Link REST is a community-maintained Apollo Link that enables GraphQL clients to query existing REST APIs using GraphQL syntax. Current stable version is 0.10.0-rc.2 (release candidate). It allows prototyping, integrating with third-party REST services, and gradual migration from REST to GraphQL without a full GraphQL server. Key differentiators: works with Apollo Client, supports multiple endpoints, custom fetch, header/credential configuration, and field name normalization. Released irregularly; under active development by community.

npm install apollo-link-rest
INSTALL
IMPORT
SIG · APOLLO-LINK-REST
A
apollo-link-rest
apijavascriptv0.10.0-rc.2
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.

RestLink
import { RestLink } from 'apollo-link-rest'
import RestLink from 'apollo-link-rest'
Named export required; default import is undefined.
RestLinkOptions
import { RestLinkOptions } from 'apollo-link-rest'
TypeScript type export for options configuration.
restLink
const restLink = new RestLink({ uri: 'https://api.example.com/' });
const restLink = new restLink.RestLink({ uri: '...' });
Always instantiate with 'new'.
Link
import { ApolloLink } from '@apollo/client'; const link = ApolloLink.from([restLink, httpLink]);
import { link } from 'apollo-link-rest'
RestLink class is used to create a link instance; composition uses ApolloClient utilities.
@Rest directive
@rest(type: "Person", path: "people/1/")
Used in GraphQL query to mark a field as a REST call.

Basic setup: create RestLink, configure ApolloClient, execute a query using @rest directive to fetch from REST API.

import { RestLink } from 'apollo-link-rest'; import { ApolloClient, InMemoryCache, gql } from '@apollo/client'; const restLink = new RestLink({ uri: 'https://swapi.co/api/' }); const client = new ApolloClient({ link: restLink, cache: new InMemoryCache(), }); const query = gql` query luke { person @rest(type: "Person", path: "people/1/") { name } } `; client.query({ query }).then(response => { console.log(response.data.person.name); });
Debug
Known issues
breakingRequires @apollo/client >=4. Version 0.9.x and earlier use @apollo/client v3.
fix
Upgrade @apollo/client to v4 or higher. See migration guide.
affects: >=0.10.0-rc.1
deprecatedapollo-link-rest is community-maintained and not officially supported by Apollo. Use at your own risk.
fix
Consider using Apollo Client's built-in httpLink for GraphQL APIs. For REST, evaluate alternatives like graphql-request with custom fetch.
affects: >=0.8.0
gotchaRestLink must be placed before httpLink in ApolloLink chain, otherwise httpLink will swallow REST requests.
fix
Order links: ApolloLink.from([restLink, httpLink])
affects: *
breakingqs peer dependency is required for query string serialization; missing it may cause serialization errors.
fix
Install qs: npm install qs
affects: >=0.10.0-rc.2
gotchaThe @rest directive path is relative to the RestLink uri or endpoints configuration. Absolute paths are not supported.
fix
Use relative paths in the @rest directive, e.g., path: 'people/1/' not 'https://api.example.com/people/1/'
affects: *
breakingVersion 0.10.0-rc.2 is a release candidate; API may change before final release.
fix
Pin to exact version or wait for stable release.
affects: 0.10.0-rc.2
Errors
Common errors & fixes
TypeError: Cannot read property 'RestLink' of undefined
Attempting to use default import instead of named import.
fix
Use import { RestLink } from 'apollo-link-rest';
Module not found: Can't resolve 'qs'
Missing peer dependency qs.
fix
Run npm install qs and ensure it's in package.json.
Error: The @rest directive requires a 'path' argument
Missing path attribute in @rest directive.
fix
Add path: 'your/path' to the @rest directive, e.g., @rest(type: 'TypeName', path: 'resource/id')
Network error: Failed to fetch
CORS issue or invalid endpoint URI. The REST API may not be accessible from browser.
fix
Ensure the URI is correct and the server allows CORS. Use customFetch for proxy if needed.
TypeError: restoreLink is not a constructor
Typo in variable name or importing wrong package.
fix
Double-check import path (apollo-link-rest) and use new RestLink(...).
Upgrade
Version history
0.10.0-rc.2latest on npm
Audit
Dependencies
@apollo/clientrequiredpeer dependency for Apollo Client integration
graphqlrequiredpeer dependency required for GraphQL query parsing
qsoptionalpeer dependency for query string serialization
Agent activity
60 hits · last 30 days
node
52
Perplexity
1
OpenAI (training)
1
Resources