Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
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 2 months 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 4 years ago)
- Default Branch: master
- Last Pushed: 2023-01-07T14:49:32.000Z (over 1 year ago)
- Last Synced: 2024-07-06T14:21:50.391Z (2 months 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: 4
- 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
[![CI](https://img.shields.io/github/workflow/status/dai-shi/apollo-link-lazy/CI)](https://github.com/dai-shi/apollo-link-lazy/actions?query=workflow%3ACI)
[![npm](https://img.shields.io/npm/v/apollo-link-lazy)](https://www.npmjs.com/package/apollo-link-lazy)
[![size](https://img.shields.io/bundlephobia/minzip/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)