@magnicache/client
v1.0.1
Published
Client-side caching layer for GraphQL
Downloads
12
Readme
Magnicache/client
A lightweight client-side GraphQL caching solution that optimizes queries by atomizing complex queries and caching them individually. MagniClient utilizes localStorage to cache query results across sessions. Configurable cache size.
How to use @magnicache/client in your GraphQL client
- Install MagniCache Client.
npm i @magnicache/client
- Import MagniCache Client.
const MagniClient = require('@magnicache/client');
- Declare a new instance of MagniClient, optionally passing in a cache capacity(defaults to 40).
const magniClient = new MagniClient(maxSize);
- Invoke magniClient.query, passing in the query string and the graphql endpoint.
magniClient
.query(
`query {
person(personID: 1) {
name
eyeColor
height
}
}`,
'/graphql'
)
.then((response) => {
const queryData = response[0];
const cacheStatus = response[1];
// Handle the response data
})
.catch((err) => {
// Handle errors
});