UNPKG

@pothos/core

Version:

Pothos (formerly GiraphQL) is a plugin based schema builder for creating code-first GraphQL schemas in typescript

46 lines (45 loc) 1.25 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); function _export(target, all) { for(var name in all)Object.defineProperty(target, name, { enumerable: true, get: Object.getOwnPropertyDescriptor(all, name).get }); } _export(exports, { get contextCacheSymbol () { return contextCacheSymbol; }, get createContextCache () { return createContextCache; }, get initContextCache () { return initContextCache; } }); const contextCacheSymbol = Symbol.for('Pothos.contextCache'); function initContextCache() { return { [contextCacheSymbol]: {} }; } function createContextCache(create) { const cache = new WeakMap(); const getOrCreate = (context, ...args)=>{ const cacheKey = context[contextCacheSymbol] || context; if (cache.has(cacheKey)) { return cache.get(cacheKey); } const entry = create(context, ...args); cache.set(cacheKey, entry); return entry; }; getOrCreate.delete = (context)=>{ const cacheKey = context[contextCacheSymbol] || context; cache.delete(cacheKey); }; return getOrCreate; } //# sourceMappingURL=context-cache.js.map