@envelop/validation-cache 5.0.0-alpha-a07c198b.0 → 5.0.0-alpha-20220902173253-1ce5e1b0
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/README.md +5 -0
- package/cjs/index.js +5 -6
- package/esm/index.js +5 -6
- package/package.json +5 -4
- package/typings/index.d.cts +1 -1
- package/typings/index.d.ts +1 -1
package/README.md
CHANGED
|
@@ -13,10 +13,15 @@ yarn add @envelop/validation-cache
|
|
|
13
13
|
## Usage Example
|
|
14
14
|
|
|
15
15
|
```ts
|
|
16
|
+
import { parse, validate, execute, subscribe } from 'graphql'
|
|
16
17
|
import { envelop } from '@envelop/core'
|
|
17
18
|
import { useValidationCache } from '@envelop/validation-cache'
|
|
18
19
|
|
|
19
20
|
const getEnveloped = envelop({
|
|
21
|
+
parse,
|
|
22
|
+
validate,
|
|
23
|
+
execute,
|
|
24
|
+
subscribe,
|
|
20
25
|
plugins: [
|
|
21
26
|
// ... other plugins ...
|
|
22
27
|
useValidationCache({
|
package/cjs/index.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.useValidationCache = void 0;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
|
-
const graphql_1 = require("
|
|
5
|
+
const graphql_1 = require("graphql");
|
|
6
6
|
const lru_cache_1 = tslib_1.__importDefault(require("lru-cache"));
|
|
7
7
|
const DEFAULT_MAX = 1000;
|
|
8
8
|
const DEFAULT_TTL = 3600000;
|
|
@@ -16,25 +16,24 @@ const useValidationCache = (pluginOptions = {}) => {
|
|
|
16
16
|
});
|
|
17
17
|
return {
|
|
18
18
|
onSchemaChange() {
|
|
19
|
-
var _a, _b;
|
|
20
19
|
if (resultCache.reset) {
|
|
21
|
-
|
|
20
|
+
resultCache.reset?.();
|
|
22
21
|
}
|
|
23
22
|
else if ('clear' in resultCache) {
|
|
24
|
-
|
|
23
|
+
resultCache.clear?.();
|
|
25
24
|
}
|
|
26
25
|
},
|
|
27
26
|
onParse({ params, extendContext }) {
|
|
28
27
|
extendContext({ [rawDocumentSymbol]: params.source.toString() });
|
|
29
28
|
},
|
|
30
29
|
onValidate({ params, context, setResult }) {
|
|
31
|
-
|
|
32
|
-
const key = (_a = context[rawDocumentSymbol]) !== null && _a !== void 0 ? _a : (0, graphql_1.print)(params.documentAST);
|
|
30
|
+
const key = context[rawDocumentSymbol] ?? (0, graphql_1.print)(params.documentAST);
|
|
33
31
|
const cachedResult = resultCache.get(key);
|
|
34
32
|
if (cachedResult !== undefined) {
|
|
35
33
|
setResult(cachedResult);
|
|
36
34
|
}
|
|
37
35
|
return ({ result }) => {
|
|
36
|
+
// @ts-expect-error TODO: not sure how we will make it dev friendly
|
|
38
37
|
resultCache.set(key, result);
|
|
39
38
|
};
|
|
40
39
|
},
|
package/esm/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { print } from '
|
|
1
|
+
import { print } from 'graphql';
|
|
2
2
|
import LRU from 'lru-cache';
|
|
3
3
|
const DEFAULT_MAX = 1000;
|
|
4
4
|
const DEFAULT_TTL = 3600000;
|
|
@@ -12,25 +12,24 @@ export const useValidationCache = (pluginOptions = {}) => {
|
|
|
12
12
|
});
|
|
13
13
|
return {
|
|
14
14
|
onSchemaChange() {
|
|
15
|
-
var _a, _b;
|
|
16
15
|
if (resultCache.reset) {
|
|
17
|
-
|
|
16
|
+
resultCache.reset?.();
|
|
18
17
|
}
|
|
19
18
|
else if ('clear' in resultCache) {
|
|
20
|
-
|
|
19
|
+
resultCache.clear?.();
|
|
21
20
|
}
|
|
22
21
|
},
|
|
23
22
|
onParse({ params, extendContext }) {
|
|
24
23
|
extendContext({ [rawDocumentSymbol]: params.source.toString() });
|
|
25
24
|
},
|
|
26
25
|
onValidate({ params, context, setResult }) {
|
|
27
|
-
|
|
28
|
-
const key = (_a = context[rawDocumentSymbol]) !== null && _a !== void 0 ? _a : print(params.documentAST);
|
|
26
|
+
const key = context[rawDocumentSymbol] ?? print(params.documentAST);
|
|
29
27
|
const cachedResult = resultCache.get(key);
|
|
30
28
|
if (cachedResult !== undefined) {
|
|
31
29
|
setResult(cachedResult);
|
|
32
30
|
}
|
|
33
31
|
return ({ result }) => {
|
|
32
|
+
// @ts-expect-error TODO: not sure how we will make it dev friendly
|
|
34
33
|
resultCache.set(key, result);
|
|
35
34
|
};
|
|
36
35
|
},
|
package/package.json
CHANGED
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@envelop/validation-cache",
|
|
3
|
-
"version": "5.0.0-alpha-
|
|
3
|
+
"version": "5.0.0-alpha-20220902173253-1ce5e1b0",
|
|
4
4
|
"sideEffects": false,
|
|
5
5
|
"peerDependencies": {
|
|
6
|
-
"@envelop/core": "3.0.0-alpha-
|
|
7
|
-
"
|
|
6
|
+
"@envelop/core": "3.0.0-alpha-20220902173253-1ce5e1b0",
|
|
7
|
+
"graphql": "^14.0.0 || ^15.0.0 || ^16.0.0"
|
|
8
8
|
},
|
|
9
9
|
"dependencies": {
|
|
10
|
-
"lru-cache": "^6.0.0"
|
|
10
|
+
"lru-cache": "^6.0.0",
|
|
11
|
+
"tslib": "^2.4.0"
|
|
11
12
|
},
|
|
12
13
|
"repository": {
|
|
13
14
|
"type": "git",
|
package/typings/index.d.cts
CHANGED
package/typings/index.d.ts
CHANGED