@envelop/validation-cache 2.2.1 → 2.3.1-alpha-33ac2d1.0
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/index.js +7 -2
- package/index.mjs +7 -2
- package/package.json +4 -3
package/index.js
CHANGED
|
@@ -9,14 +9,19 @@ const lru = _interopDefault(require('tiny-lru'));
|
|
|
9
9
|
|
|
10
10
|
const DEFAULT_MAX = 1000;
|
|
11
11
|
const DEFAULT_TTL = 3600000;
|
|
12
|
+
const rawDocumentSymbol = Symbol('rawDocument');
|
|
12
13
|
const useValidationCache = (pluginOptions = {}) => {
|
|
13
14
|
const resultCache = typeof pluginOptions.cache !== 'undefined' ? pluginOptions.cache : lru(DEFAULT_MAX, DEFAULT_TTL);
|
|
14
15
|
return {
|
|
15
16
|
onSchemaChange() {
|
|
16
17
|
resultCache.clear();
|
|
17
18
|
},
|
|
18
|
-
|
|
19
|
-
|
|
19
|
+
onParse({ params, extendContext }) {
|
|
20
|
+
extendContext({ [rawDocumentSymbol]: params.source.toString() });
|
|
21
|
+
},
|
|
22
|
+
onValidate({ params, context, setResult }) {
|
|
23
|
+
var _a;
|
|
24
|
+
const key = (_a = context[rawDocumentSymbol]) !== null && _a !== void 0 ? _a : graphql.print(params.documentAST);
|
|
20
25
|
const cachedResult = resultCache.get(key);
|
|
21
26
|
if (cachedResult !== undefined) {
|
|
22
27
|
setResult(cachedResult);
|
package/index.mjs
CHANGED
|
@@ -3,14 +3,19 @@ import lru from 'tiny-lru';
|
|
|
3
3
|
|
|
4
4
|
const DEFAULT_MAX = 1000;
|
|
5
5
|
const DEFAULT_TTL = 3600000;
|
|
6
|
+
const rawDocumentSymbol = Symbol('rawDocument');
|
|
6
7
|
const useValidationCache = (pluginOptions = {}) => {
|
|
7
8
|
const resultCache = typeof pluginOptions.cache !== 'undefined' ? pluginOptions.cache : lru(DEFAULT_MAX, DEFAULT_TTL);
|
|
8
9
|
return {
|
|
9
10
|
onSchemaChange() {
|
|
10
11
|
resultCache.clear();
|
|
11
12
|
},
|
|
12
|
-
|
|
13
|
-
|
|
13
|
+
onParse({ params, extendContext }) {
|
|
14
|
+
extendContext({ [rawDocumentSymbol]: params.source.toString() });
|
|
15
|
+
},
|
|
16
|
+
onValidate({ params, context, setResult }) {
|
|
17
|
+
var _a;
|
|
18
|
+
const key = (_a = context[rawDocumentSymbol]) !== null && _a !== void 0 ? _a : print(params.documentAST);
|
|
14
19
|
const cachedResult = resultCache.get(key);
|
|
15
20
|
if (cachedResult !== undefined) {
|
|
16
21
|
setResult(cachedResult);
|
package/package.json
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@envelop/validation-cache",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.3.1-alpha-33ac2d1.0",
|
|
4
4
|
"sideEffects": false,
|
|
5
5
|
"peerDependencies": {
|
|
6
|
-
"@envelop/core": "
|
|
6
|
+
"@envelop/core": "1.6.6-alpha-33ac2d1.0",
|
|
7
7
|
"graphql": "^14.0.0 || ^15.0.0 || ^16.0.0"
|
|
8
8
|
},
|
|
9
9
|
"dependencies": {
|
|
@@ -30,6 +30,7 @@
|
|
|
30
30
|
"./*": {
|
|
31
31
|
"require": "./*.js",
|
|
32
32
|
"import": "./*.mjs"
|
|
33
|
-
}
|
|
33
|
+
},
|
|
34
|
+
"./package.json": "./package.json"
|
|
34
35
|
}
|
|
35
36
|
}
|