Skip to content

Commit

Permalink
Update LRU Cache package (dotansimha#2801)
Browse files Browse the repository at this point in the history
* Update LRU Cache

* chore(dependencies): updated changesets for modified dependencies

---------

Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
  • Loading branch information
ardatan and github-actions[bot] authored May 26, 2023
1 parent 7bb2703 commit 6f83c0c
Show file tree
Hide file tree
Showing 10 changed files with 35 additions and 32 deletions.
5 changes: 5 additions & 0 deletions .changeset/@graphql-yoga_plugin-apq-2801-dependencies.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@graphql-yoga/plugin-apq': patch
---
dependencies updates:
- Removed dependency [`lru-cache@^7.14.1` ↗︎](https://www.npmjs.com/package/lru-cache/v/7.14.1) (from `dependencies`)
5 changes: 5 additions & 0 deletions .changeset/graphql-yoga-2801-dependencies.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'graphql-yoga': patch
---
dependencies updates:
- Updated dependency [`lru-cache@^9.0.0` ↗︎](https://www.npmjs.com/package/lru-cache/v/9.0.0) (from `^7.14.1`, in `dependencies`)
2 changes: 1 addition & 1 deletion import-map.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,6 @@
"@whatwg-node/events": "npm:@whatwg-node/[email protected]",
"@whatwg-node/server": "npm:@whatwg-node/server",
"@repeaterjs/repeater": "npm:@repeaterjs/repeater",
"lru-cache": "npm:lru-cache@^7.14.1"
"lru-cache": "npm:lru-cache@^9.0.0"
}
}
2 changes: 1 addition & 1 deletion packages/graphql-yoga/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
"@whatwg-node/fetch": "^0.9.0",
"@whatwg-node/server": "^0.8.0",
"dset": "^3.1.1",
"lru-cache": "^7.14.1",
"lru-cache": "^9.0.0",
"tslib": "^2.5.2"
},
"devDependencies": {
Expand Down
1 change: 1 addition & 0 deletions packages/graphql-yoga/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export * from './server.js'
export * from './subscription.js'
export * from './types.js'
export { maskError } from './utils/mask-error.js'
export { createLRUCache } from './utils/create-lru-cache.js'
export type {
// Handy type utils
Maybe,
Expand Down
16 changes: 13 additions & 3 deletions packages/graphql-yoga/src/utils/create-lru-cache.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,18 @@
import LRU from 'lru-cache'
/* eslint-disable @typescript-eslint/ban-types */
import { LRUCache as LRU } from 'lru-cache'

const DEFAULT_MAX = 1024
const DEFAULT_TTL = 3_600_000

export function createLRUCache<T>() {
return new LRU<string, T>({ max: DEFAULT_MAX, ttl: DEFAULT_TTL })
export type LRUCache<T extends {}> = LRU<string, T>
export interface LRUCacheOptions {
max?: number
ttl?: number
}

export function createLRUCache<T extends {}>({
max = DEFAULT_MAX,
ttl = DEFAULT_TTL,
}: LRUCacheOptions = {}) {
return new LRU<string, T>({ max, ttl })
}
3 changes: 0 additions & 3 deletions packages/plugins/apq/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,6 @@
"directory": "dist",
"access": "public"
},
"dependencies": {
"lru-cache": "^7.14.1"
},
"devDependencies": {
"graphql-yoga": "3.9.1"
},
Expand Down
10 changes: 7 additions & 3 deletions packages/plugins/apq/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
import { createGraphQLError, Plugin, PromiseOrValue } from 'graphql-yoga'
import LRU from 'lru-cache'
import {
createGraphQLError,
Plugin,
PromiseOrValue,
createLRUCache,
} from 'graphql-yoga'

export async function hashSHA256(
str: string,
Expand Down Expand Up @@ -27,7 +31,7 @@ export interface APQStoreOptions {
export function createInMemoryAPQStore(
options: APQStoreOptions = {},
): APQStore {
return new LRU({
return createLRUCache<string>({
max: options.max ?? 1000,
ttl: options.ttl ?? 36_000,
})
Expand Down
1 change: 0 additions & 1 deletion packages/plugins/persisted-operations/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@
"graphql-yoga": "^3.9.1"
},
"devDependencies": {
"@types/lru-cache": "7.10.9",
"graphql-yoga": "^3.9.1"
},
"type": "module"
Expand Down
22 changes: 2 additions & 20 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 6f83c0c

Please sign in to comment.