UNPKG

graphql-react

Version:

A GraphQL client for React using modern context and hooks APIs that’s lightweight (< 4 kB) but powerful; the first Relay and Apollo alternative with server side rendering.

28 lines (24 loc) 1 kB
import Cache from "./Cache.mjs"; import cacheEntryPrune from "./cacheEntryPrune.mjs"; /** * Prunes [cache]{@link Cache#store} entries. Useful after a mutation. * @kind function * @name cachePrune * @param {Cache} cache Cache to update. * @param {CacheKeyMatcher} [cacheKeyMatcher] Matches [cache keys]{@link CacheKey} to prune. By default all are matched. * @fires Cache#event:prune * @fires Cache#event:delete * @example <caption>How to import.</caption> * ```js * import cachePrune from "graphql-react/cachePrune.mjs"; * ``` */ export default function cachePrune(cache, cacheKeyMatcher) { if (!(cache instanceof Cache)) throw new TypeError("Argument 1 `cache` must be a `Cache` instance."); if (cacheKeyMatcher !== undefined && typeof cacheKeyMatcher !== "function") throw new TypeError("Argument 2 `cacheKeyMatcher` must be a function."); for (const cacheKey in cache.store) if (!cacheKeyMatcher || cacheKeyMatcher(cacheKey)) cacheEntryPrune(cache, cacheKey); }