@envelop/validation-cache
Advanced tools
Comparing version 1.1.0-alpha-d7e3951.0 to 2.0.0
import { Plugin } from '@envelop/types'; | ||
import { GraphQLError } from 'graphql'; | ||
export interface ValidationCache { | ||
get(key: string): readonly GraphQLError[] | undefined; | ||
set(key: string, value: readonly GraphQLError[]): void; | ||
clear(): void; | ||
} | ||
export declare type ValidationCacheOptions = { | ||
max?: number; | ||
ttl?: number; | ||
cache?: ValidationCache; | ||
}; | ||
export declare const useValidationCache: (pluginOptions?: ValidationCacheOptions) => Plugin; |
12
index.js
@@ -13,5 +13,3 @@ 'use strict'; | ||
const useValidationCache = (pluginOptions = {}) => { | ||
const max = typeof pluginOptions.max === 'number' ? pluginOptions.max : DEFAULT_MAX; | ||
const ttl = typeof pluginOptions.ttl === 'number' ? pluginOptions.ttl : DEFAULT_TTL; | ||
const resultCache = lru(max, ttl); | ||
const resultCache = typeof pluginOptions.cache !== 'undefined' ? pluginOptions.cache : lru(DEFAULT_MAX, DEFAULT_TTL); | ||
return { | ||
@@ -23,7 +21,5 @@ onSchemaChange() { | ||
const key = graphql.print(params.documentAST); | ||
if (resultCache.get(key)) { | ||
const errors = resultCache.get(key); | ||
if (errors) { | ||
setResult(errors); | ||
} | ||
const cachedResult = resultCache.get(key); | ||
if (cachedResult !== undefined) { | ||
setResult(cachedResult); | ||
} | ||
@@ -30,0 +26,0 @@ return ({ result }) => { |
{ | ||
"name": "@envelop/validation-cache", | ||
"version": "1.1.0-alpha-d7e3951.0", | ||
"version": "2.0.0", | ||
"sideEffects": false, | ||
"peerDependencies": { | ||
"graphql": "^14.0.0 || ^15.0.0 || ^16.0.0" | ||
"graphql": "^14.0.0 || ^15.0.0" | ||
}, | ||
@@ -8,0 +8,0 @@ "dependencies": { |
@@ -31,8 +31,4 @@ ## `@envelop/validation-cache` | ||
#### `max` | ||
#### `cache` | ||
Set this to configure your maximum amount of items in the LRU cache. The default is `1000`. | ||
#### `ttl` | ||
Set this to configure the TTL (time to live) of items in the LRU cache. The default is `3600000`. | ||
Set this to pass in a cache instance. By default a new LRU cache is created using default `max` and `ttl`. |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
1
3660
60
34