All Projects → kamilkisiela → Apollo Link Maxage

kamilkisiela / Apollo Link Maxage

Licence: mit
An Apollo Link to invalidate cached queries

Programming Languages

typescript
32286 projects

Projects that are alternatives of or similar to Apollo Link Maxage

Link state demo
🚀 Demonstrate how to support multiple stores in Apollo Link State
Stars: ✭ 30 (+30.43%)
Mutual labels:  graphql, apollo-client, apollographql
Graphql Codegen Hasura
code-generator plugins for hasura/apollo-gql/typescript development
Stars: ✭ 113 (+391.3%)
Mutual labels:  graphql, apollo-client, apollographql
Githunt React
[DEPRECATED] 🔃 An example app frontend built with Apollo Client and React
Stars: ✭ 1,036 (+4404.35%)
Mutual labels:  graphql, apollo-client, apollographql
React Graphql Github Apollo
🚀 A React + Apollo + GraphQL GitHub Client. Your opportunity to learn about these technologies in a real world application.
Stars: ✭ 1,563 (+6695.65%)
Mutual labels:  graphql, apollo-client, apollographql
Apollo Angular
A fully-featured, production ready caching GraphQL client for Angular and every GraphQL server 🎁
Stars: ✭ 1,058 (+4500%)
Mutual labels:  graphql, apollo-client, apollographql
Apollo Client
🚀  A fully-featured, production ready caching GraphQL client for every UI framework and GraphQL server.
Stars: ✭ 17,070 (+74117.39%)
Mutual labels:  graphql, apollo-client, apollographql
Lucid
A developer tool for engineers working with React and GraphQL.
Stars: ✭ 397 (+1626.09%)
Mutual labels:  graphql, apollographql
Apollo Errors
Machine-readable custom errors for Apollostack's GraphQL server
Stars: ✭ 405 (+1660.87%)
Mutual labels:  graphql, apollo-client
Apollo Link Firebase
🔥 🔗 apollo-link-firebase provides you a simple way to use Firebase with graphQL.
Stars: ✭ 415 (+1704.35%)
Mutual labels:  graphql, apollo-client
Apollo Resolvers
Expressive and composable resolvers for Apollostack's GraphQL server
Stars: ✭ 428 (+1760.87%)
Mutual labels:  graphql, apollo-client
Graphback
Graphback - Out of the box GraphQL server and client
Stars: ✭ 323 (+1304.35%)
Mutual labels:  graphql, apollographql
Graphql Up
Get a ready-to-use GraphQL API for your schema
Stars: ✭ 415 (+1704.35%)
Mutual labels:  graphql, apollographql
Fraql
GraphQL fragments made simple ⚡️
Stars: ✭ 433 (+1782.61%)
Mutual labels:  graphql, apollographql
Absinthe
The GraphQL toolkit for Elixir
Stars: ✭ 3,805 (+16443.48%)
Mutual labels:  graphql, apollo-client
Apollo Storybook Decorator
Wrap your storybook environment with Apollo Client, provide mocks for isolated UI testing with GraphQL
Stars: ✭ 333 (+1347.83%)
Mutual labels:  graphql, apollo-client
Persistgraphql
A build tool for GraphQL projects.
Stars: ✭ 409 (+1678.26%)
Mutual labels:  graphql, apollo-client
Relate
[ARCHIVED] experimenting React + GraphQL + Next.js web app on the theme of mindfulness
Stars: ✭ 324 (+1308.7%)
Mutual labels:  graphql, apollographql
Apollo Cache Hermes
A cache implementation for Apollo Client, tuned for performance
Stars: ✭ 425 (+1747.83%)
Mutual labels:  graphql, apollo-client
Chatty
A WhatsApp clone with React Native and Apollo (Tutorial)
Stars: ✭ 481 (+1991.3%)
Mutual labels:  graphql, apollo-client
Get Graphql Schema
Fetch and print the GraphQL schema from a GraphQL HTTP endpoint. (Can be used for Relay Modern.)
Stars: ✭ 443 (+1826.09%)
Mutual labels:  graphql, apollographql

MaxAge ApolloLink

npm version CircleCI

Purpose

An Apollo Link to invalidate cached queries.

Installation

yarn add apollo-link-maxage
npm install --save apollo-link-maxage

Usage

Simply specify maxAge in a query's context. This could be a number of ms or a string (i.e. 10s for 10 seconds, 5m for 5 minutes etc.).

import { MaxAgeLink } from 'apollo-link-maxage';
import { InMemoryCache } from 'apollo-inmemory-cache';

const myCache = new InMemoryCache();
const maxAgeLink = new MaxAgeLink({
  cache: myCache,
});
// query options
{
  query: gql`
    query me {
      me {
        name
      }
    }
  `,
  fetchPolicy: 'network-only',
  context: {
    maxAge: '5m', // or 300000 (5m in ms)
  },
}

NOTE: It's important to set fetchPolicy to network-only or similar. This is because ApolloClient won't execute a Link if there is no need to fetch a result from a GraphQL endpoint.

How it works

If a query runs for a first time, it's being executed normally but the expiration date is stored. Next time it runs the MaxAgeLink checks if a query is expired, if not it reads results from cache, otherwise the process starts again.

To match a query with the one that has been stored we need to generate a unique key. By default it uses ApolloLink's toKey() method but you can define your own logic by providing a function as toKey option.

Options

  • cache - instance of ApolloCache (required)
  • toKey - a function that receives an Operation and returns a unique string ((op: Operation) => string)
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].