https://github.com/dai-shi/apollo-link-lazy
Apollo Link for lazy loading
https://github.com/dai-shi/apollo-link-lazy
apollo-client apollo-link apollographql lazy-loading
Last synced: about 1 year ago
JSON representation
Apollo Link for lazy loading
- Host: GitHub
- URL: https://github.com/dai-shi/apollo-link-lazy
- Owner: dai-shi
- License: mit
- Created: 2020-01-06T15:33:54.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2023-01-07T14:49:32.000Z (over 3 years ago)
- Last Synced: 2025-03-28T13:05:29.132Z (about 1 year ago)
- Topics: apollo-client, apollo-link, apollographql, lazy-loading
- Language: JavaScript
- Homepage: https://www.npmjs.com/package/apollo-link-lazy
- Size: 2.8 MB
- Stars: 14
- Watchers: 3
- Forks: 1
- Open Issues: 21
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
- awesome-list - apollo-link-lazy - shi | 9 | (JavaScript)
README
# apollo-link-lazy
[](https://github.com/dai-shi/apollo-link-lazy/actions?query=workflow%3ACI)
[](https://www.npmjs.com/package/apollo-link-lazy)
[](https://bundlephobia.com/result?p=apollo-link-lazy)
Apollo Link for lazy loading
## Introduction
This is a tiny library to lazy load Apollo Link.
It can be useful for code splitting.
## Install
```bash
npm install apollo-link-lazy
```
## Usage
```javascript
import ApolloClient from 'apollo-client';
import { InMemoryCache } from 'apollo-cache-inmemory';
import { lazy } from 'apollo-link-lazy';
const client = new ApolloClient({
cache: new InMemoryCache(),
link: lazy(() => import('./link')),
});
```
## API
### lazy
Lazy load ApolloLink promise
Type: Lazy
#### Parameters
- `factory`
#### Examples
```javascript
import { lazy } from 'apollo-link-lazy';
const link = lazy(() => import('./link'));
```
## Examples
The [examples](examples) folder contains working examples.
You can run one of them with
```bash
PORT=8080 npm run examples:01_minimal
```
and open in your web browser.
You can also try them in codesandbox.io:
[01](https://codesandbox.io/s/github/dai-shi/apollo-link-lazy/tree/master/examples/01_minimal)
[02](https://codesandbox.io/s/github/dai-shi/apollo-link-lazy/tree/master/examples/02_typescript)