From 17eb81bd389ab449e96ba686285bc22846807f82 Mon Sep 17 00:00:00 2001 From: Arda TANRIKULU Date: Tue, 24 Dec 2024 11:08:28 +0300 Subject: [PATCH] Mark `createLRUCache` as an internal utility --- .changeset/thirty-jokes-compare.md | 6 +++ packages/graphql-yoga/src/index.ts | 2 +- .../use-parser-and-validation-cache.ts | 8 ++-- .../src/utils/create-lru-cache.ts | 39 ++++++++++++++++--- 4 files changed, 45 insertions(+), 10 deletions(-) create mode 100644 .changeset/thirty-jokes-compare.md diff --git a/.changeset/thirty-jokes-compare.md b/.changeset/thirty-jokes-compare.md new file mode 100644 index 000000000..81b4f03e0 --- /dev/null +++ b/.changeset/thirty-jokes-compare.md @@ -0,0 +1,6 @@ +--- +'graphql-yoga': patch +--- + +Mark `createLRUCache` utility as deprecated, and export it as `_createLRUCache` marking it as an +internal utility diff --git a/packages/graphql-yoga/src/index.ts b/packages/graphql-yoga/src/index.ts index c19de1439..a886a53ba 100644 --- a/packages/graphql-yoga/src/index.ts +++ b/packages/graphql-yoga/src/index.ts @@ -10,7 +10,7 @@ export * from './subscription.js'; export * from './types.js'; export { maskError } from './utils/mask-error.js'; export { type OnParamsEventPayload } from './plugins/types.js'; -export { createLRUCache } from './utils/create-lru-cache.js'; +export { _createLRUCache, createLRUCache } from './utils/create-lru-cache.js'; export { mergeSchemas } from '@graphql-tools/schema'; export { // Handy type utils diff --git a/packages/graphql-yoga/src/plugins/use-parser-and-validation-cache.ts b/packages/graphql-yoga/src/plugins/use-parser-and-validation-cache.ts index 802ebbf0f..d6df3a7f7 100644 --- a/packages/graphql-yoga/src/plugins/use-parser-and-validation-cache.ts +++ b/packages/graphql-yoga/src/plugins/use-parser-and-validation-cache.ts @@ -1,6 +1,6 @@ import type { DocumentNode, GraphQLError, GraphQLSchema, validate, ValidationRule } from 'graphql'; import type { AfterValidateHook } from '@envelop/core'; -import { createLRUCache } from '../utils/create-lru-cache.js'; +import { _createLRUCache } from '../utils/create-lru-cache.js'; import type { Plugin } from './types.js'; interface Cache { @@ -15,13 +15,13 @@ export interface ParserAndValidationCacheOptions { } export function useParserAndValidationCache({ - documentCache = createLRUCache(), - errorCache = createLRUCache(), + documentCache = _createLRUCache(), + errorCache = _createLRUCache(), validationCache = true, }: // eslint-disable-next-line @typescript-eslint/no-empty-object-type ParserAndValidationCacheOptions): Plugin<{}> { const validationCacheByRules = - createLRUCache>>(); + _createLRUCache>>(); return { onParse({ params, setParsedDocument }) { const strDocument = params.source.toString(); diff --git a/packages/graphql-yoga/src/utils/create-lru-cache.ts b/packages/graphql-yoga/src/utils/create-lru-cache.ts index f6021dedb..17b0ae2f4 100644 --- a/packages/graphql-yoga/src/utils/create-lru-cache.ts +++ b/packages/graphql-yoga/src/utils/create-lru-cache.ts @@ -1,18 +1,47 @@ /* eslint-disable @typescript-eslint/no-empty-object-type */ import { LRUCache as LRU } from 'lru-cache'; +/** + * @deprecated In the next major, `createLRUCache` will be renamed to `_createLRUCache`, + * and the current `createLRUCache` will be removed. + */ +export const createLRUCache = _createLRUCache; + +/** + * @deprecated In the next major, `LRUCacheOptions` will be renamed to `_LRUCacheOptions`, + * and the current `LRUCacheOptions` will be removed. + */ +export type LRUCacheOptions = _LRUCacheOptions; + +/** + * @deprecated In the next major, `LRUCache` will be renamed to `_LRUCache`, + * and the current `LRUCache` will be removed. + */ +export type LRUCache = _LRUCache; + const DEFAULT_MAX = 1024; const DEFAULT_TTL = 3_600_000; -export type LRUCache = LRU; -export interface LRUCacheOptions { +/** + * @internal This is an internal utility, and you should use it with your own risk. + * This utility can have breaking changes in the future. + */ +export type _LRUCache = LRU; +/** + * @internal This is an internal utility, and you should use it with your own risk. + * This utility can have breaking changes in the future. + */ +export interface _LRUCacheOptions { max?: number; ttl?: number; } - -export function createLRUCache({ +/** + * @internal This is an internal utility, and you should use it with your own risk. + * This utility can have breaking changes in the future. + */ +export function _createLRUCache({ max = DEFAULT_MAX, ttl = DEFAULT_TTL, -}: LRUCacheOptions = {}) { +}: _LRUCacheOptions = {}) { return new LRU({ max, ttl }); }