@envelop/validation-cache 5.1.2 → 5.1.3-alpha-20230220175948-cdba6d9f
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/cjs/index.js +3 -6
- package/esm/index.js +3 -6
- package/package.json +2 -2
package/cjs/index.js
CHANGED
|
@@ -2,13 +2,13 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.useValidationCache = void 0;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
|
+
const core_1 = require("@envelop/core");
|
|
5
6
|
const graphql_1 = require("graphql");
|
|
6
7
|
const fast_json_stable_stringify_1 = tslib_1.__importDefault(require("fast-json-stable-stringify"));
|
|
7
8
|
const lru_cache_1 = tslib_1.__importDefault(require("lru-cache"));
|
|
8
9
|
const sha1_es_1 = tslib_1.__importDefault(require("sha1-es"));
|
|
9
10
|
const DEFAULT_MAX = 1000;
|
|
10
11
|
const DEFAULT_TTL = 3600000;
|
|
11
|
-
const rawDocumentSymbol = Symbol('rawDocument');
|
|
12
12
|
const schemaHashCache = new WeakMap();
|
|
13
13
|
function getSchemaHash(schema) {
|
|
14
14
|
let hash = schemaHashCache.get(schema);
|
|
@@ -28,10 +28,7 @@ const useValidationCache = (pluginOptions = {}) => {
|
|
|
28
28
|
maxAge: DEFAULT_TTL,
|
|
29
29
|
});
|
|
30
30
|
return {
|
|
31
|
-
|
|
32
|
-
extendContext({ [rawDocumentSymbol]: params.source.toString() });
|
|
33
|
-
},
|
|
34
|
-
onValidate({ params, context, setValidationFn, validateFn }) {
|
|
31
|
+
onValidate({ params, setValidationFn, validateFn }) {
|
|
35
32
|
// We use setValidateFn over accessing params.rules directly, as other plugins in the chain might add more rules.
|
|
36
33
|
// This would cause an issue if we are constructing the cache key here already.
|
|
37
34
|
setValidationFn((...args) => {
|
|
@@ -43,7 +40,7 @@ const useValidationCache = (pluginOptions = {}) => {
|
|
|
43
40
|
ruleKey = ruleKey + rule.name;
|
|
44
41
|
}
|
|
45
42
|
}
|
|
46
|
-
const key = schemaHashKey + `|` + ruleKey + `|` + (
|
|
43
|
+
const key = schemaHashKey + `|` + ruleKey + `|` + (0, core_1.getDocumentString)(params.documentAST, graphql_1.print);
|
|
47
44
|
const cachedResult = resultCache.get(key);
|
|
48
45
|
if (cachedResult !== undefined) {
|
|
49
46
|
return cachedResult;
|
package/esm/index.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
+
import { getDocumentString } from '@envelop/core';
|
|
1
2
|
import { print, introspectionFromSchema } from 'graphql';
|
|
2
3
|
import jsonStableStringify from 'fast-json-stable-stringify';
|
|
3
4
|
import LRU from 'lru-cache';
|
|
4
5
|
import SHA1 from 'sha1-es';
|
|
5
6
|
const DEFAULT_MAX = 1000;
|
|
6
7
|
const DEFAULT_TTL = 3600000;
|
|
7
|
-
const rawDocumentSymbol = Symbol('rawDocument');
|
|
8
8
|
const schemaHashCache = new WeakMap();
|
|
9
9
|
function getSchemaHash(schema) {
|
|
10
10
|
let hash = schemaHashCache.get(schema);
|
|
@@ -24,10 +24,7 @@ export const useValidationCache = (pluginOptions = {}) => {
|
|
|
24
24
|
maxAge: DEFAULT_TTL,
|
|
25
25
|
});
|
|
26
26
|
return {
|
|
27
|
-
|
|
28
|
-
extendContext({ [rawDocumentSymbol]: params.source.toString() });
|
|
29
|
-
},
|
|
30
|
-
onValidate({ params, context, setValidationFn, validateFn }) {
|
|
27
|
+
onValidate({ params, setValidationFn, validateFn }) {
|
|
31
28
|
// We use setValidateFn over accessing params.rules directly, as other plugins in the chain might add more rules.
|
|
32
29
|
// This would cause an issue if we are constructing the cache key here already.
|
|
33
30
|
setValidationFn((...args) => {
|
|
@@ -39,7 +36,7 @@ export const useValidationCache = (pluginOptions = {}) => {
|
|
|
39
36
|
ruleKey = ruleKey + rule.name;
|
|
40
37
|
}
|
|
41
38
|
}
|
|
42
|
-
const key = schemaHashKey + `|` + ruleKey + `|` + (
|
|
39
|
+
const key = schemaHashKey + `|` + ruleKey + `|` + getDocumentString(params.documentAST, print);
|
|
43
40
|
const cachedResult = resultCache.get(key);
|
|
44
41
|
if (cachedResult !== undefined) {
|
|
45
42
|
return cachedResult;
|
package/package.json
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@envelop/validation-cache",
|
|
3
|
-
"version": "5.1.
|
|
3
|
+
"version": "5.1.3-alpha-20230220175948-cdba6d9f",
|
|
4
4
|
"sideEffects": false,
|
|
5
5
|
"peerDependencies": {
|
|
6
|
-
"@envelop/core": "
|
|
6
|
+
"@envelop/core": "3.0.7-alpha-20230220175948-cdba6d9f",
|
|
7
7
|
"graphql": "^14.0.0 || ^15.0.0 || ^16.0.0"
|
|
8
8
|
},
|
|
9
9
|
"dependencies": {
|