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.23 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: all[name] }); } _export(exports, { contextCacheSymbol: function() { return contextCacheSymbol; }, createContextCache: function() { return createContextCache; }, initContextCache: function() { 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