Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

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

Awesome Lists containing this project

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)