@envelop/parser-cache 5.0.0-alpha-36a1267.0 → 5.0.0-alpha-5b6bfa8.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/README.md +5 -5
- package/{index.js → cjs/index.js} +11 -13
- package/cjs/package.json +1 -0
- package/{index.mjs → esm/index.js} +7 -8
- package/package.json +35 -14
- package/{index.d.ts → typings/index.d.ts} +1 -1
package/README.md
CHANGED
|
@@ -13,17 +13,17 @@ yarn add @envelop/parser-cache
|
|
|
13
13
|
## Usage Example
|
|
14
14
|
|
|
15
15
|
```ts
|
|
16
|
-
import { envelop } from '@envelop/core'
|
|
17
|
-
import { useParserCache } from '@envelop/parser-cache'
|
|
16
|
+
import { envelop } from '@envelop/core'
|
|
17
|
+
import { useParserCache } from '@envelop/parser-cache'
|
|
18
18
|
|
|
19
19
|
const getEnveloped = envelop({
|
|
20
20
|
plugins: [
|
|
21
21
|
// ... other plugins ...
|
|
22
22
|
useParserCache({
|
|
23
23
|
// options goes here
|
|
24
|
-
})
|
|
25
|
-
]
|
|
26
|
-
})
|
|
24
|
+
})
|
|
25
|
+
]
|
|
26
|
+
})
|
|
27
27
|
```
|
|
28
28
|
|
|
29
29
|
### API Reference
|
|
@@ -1,23 +1,22 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
const graphql = require('graphql');
|
|
8
|
-
const lru = _interopDefault(require('tiny-lru'));
|
|
9
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.useParserCache = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const graphql_1 = require("@graphql-tools/graphql");
|
|
6
|
+
const lru_cache_1 = tslib_1.__importDefault(require("lru-cache"));
|
|
10
7
|
const DEFAULT_MAX = 1000;
|
|
11
8
|
const DEFAULT_TTL = 3600000;
|
|
12
9
|
const useParserCache = (pluginOptions = {}) => {
|
|
13
10
|
const documentCache = typeof pluginOptions.documentCache !== 'undefined'
|
|
14
11
|
? pluginOptions.documentCache
|
|
15
|
-
:
|
|
16
|
-
const errorCache = typeof pluginOptions.errorCache !== 'undefined'
|
|
12
|
+
: new lru_cache_1.default({ max: DEFAULT_MAX, maxAge: DEFAULT_TTL });
|
|
13
|
+
const errorCache = typeof pluginOptions.errorCache !== 'undefined'
|
|
14
|
+
? pluginOptions.errorCache
|
|
15
|
+
: new lru_cache_1.default({ max: DEFAULT_MAX, maxAge: DEFAULT_TTL });
|
|
17
16
|
return {
|
|
18
17
|
onParse({ params, setParsedDocument }) {
|
|
19
18
|
const { source } = params;
|
|
20
|
-
const key = source instanceof
|
|
19
|
+
const key = source instanceof graphql_1.Source ? source.body : source;
|
|
21
20
|
const cachedError = errorCache.get(key);
|
|
22
21
|
if (cachedError !== undefined) {
|
|
23
22
|
throw cachedError;
|
|
@@ -37,5 +36,4 @@ const useParserCache = (pluginOptions = {}) => {
|
|
|
37
36
|
},
|
|
38
37
|
};
|
|
39
38
|
};
|
|
40
|
-
|
|
41
39
|
exports.useParserCache = useParserCache;
|
package/cjs/package.json
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"type":"commonjs"}
|
|
@@ -1,13 +1,14 @@
|
|
|
1
|
-
import { Source } from 'graphql';
|
|
2
|
-
import
|
|
3
|
-
|
|
1
|
+
import { Source } from '@graphql-tools/graphql';
|
|
2
|
+
import LRU from 'lru-cache';
|
|
4
3
|
const DEFAULT_MAX = 1000;
|
|
5
4
|
const DEFAULT_TTL = 3600000;
|
|
6
|
-
const useParserCache = (pluginOptions = {}) => {
|
|
5
|
+
export const useParserCache = (pluginOptions = {}) => {
|
|
7
6
|
const documentCache = typeof pluginOptions.documentCache !== 'undefined'
|
|
8
7
|
? pluginOptions.documentCache
|
|
9
|
-
:
|
|
10
|
-
const errorCache = typeof pluginOptions.errorCache !== 'undefined'
|
|
8
|
+
: new LRU({ max: DEFAULT_MAX, maxAge: DEFAULT_TTL });
|
|
9
|
+
const errorCache = typeof pluginOptions.errorCache !== 'undefined'
|
|
10
|
+
? pluginOptions.errorCache
|
|
11
|
+
: new LRU({ max: DEFAULT_MAX, maxAge: DEFAULT_TTL });
|
|
11
12
|
return {
|
|
12
13
|
onParse({ params, setParsedDocument }) {
|
|
13
14
|
const { source } = params;
|
|
@@ -31,5 +32,3 @@ const useParserCache = (pluginOptions = {}) => {
|
|
|
31
32
|
},
|
|
32
33
|
};
|
|
33
34
|
};
|
|
34
|
-
|
|
35
|
-
export { useParserCache };
|
package/package.json
CHANGED
|
@@ -1,36 +1,57 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@envelop/parser-cache",
|
|
3
|
-
"version": "5.0.0-alpha-
|
|
3
|
+
"version": "5.0.0-alpha-5b6bfa8.0",
|
|
4
4
|
"sideEffects": false,
|
|
5
5
|
"peerDependencies": {
|
|
6
|
-
"@envelop/core": "
|
|
7
|
-
"graphql": "
|
|
6
|
+
"@envelop/core": "3.0.0-alpha-5b6bfa8.0",
|
|
7
|
+
"@graphql-tools/graphql": "0.1.0-alpha-33fb2950.0"
|
|
8
8
|
},
|
|
9
9
|
"dependencies": {
|
|
10
|
-
"
|
|
10
|
+
"lru-cache": "^6.0.0"
|
|
11
11
|
},
|
|
12
12
|
"repository": {
|
|
13
13
|
"type": "git",
|
|
14
|
-
"url": "https://github.com/
|
|
14
|
+
"url": "https://github.com/n1ru4l/envelop.git",
|
|
15
15
|
"directory": "packages/plugins/parser-cache"
|
|
16
16
|
},
|
|
17
17
|
"author": "Dotan Simha <dotansimha@gmail.com>",
|
|
18
18
|
"license": "MIT",
|
|
19
|
-
"main": "index.js",
|
|
20
|
-
"module": "index.
|
|
21
|
-
"typings": "index.d.ts",
|
|
19
|
+
"main": "cjs/index.js",
|
|
20
|
+
"module": "esm/index.js",
|
|
21
|
+
"typings": "typings/index.d.ts",
|
|
22
22
|
"typescript": {
|
|
23
|
-
"definition": "index.d.ts"
|
|
23
|
+
"definition": "typings/index.d.ts"
|
|
24
24
|
},
|
|
25
|
+
"type": "module",
|
|
25
26
|
"exports": {
|
|
26
27
|
".": {
|
|
27
|
-
"require":
|
|
28
|
-
|
|
28
|
+
"require": {
|
|
29
|
+
"types": "./typings/index.d.ts",
|
|
30
|
+
"default": "./cjs/index.js"
|
|
31
|
+
},
|
|
32
|
+
"import": {
|
|
33
|
+
"types": "./typings/index.d.ts",
|
|
34
|
+
"default": "./esm/index.js"
|
|
35
|
+
},
|
|
36
|
+
"default": {
|
|
37
|
+
"types": "./typings/index.d.ts",
|
|
38
|
+
"default": "./esm/index.js"
|
|
39
|
+
}
|
|
29
40
|
},
|
|
30
41
|
"./*": {
|
|
31
|
-
"require":
|
|
32
|
-
|
|
42
|
+
"require": {
|
|
43
|
+
"types": "./typings/*.d.ts",
|
|
44
|
+
"default": "./cjs/*.js"
|
|
45
|
+
},
|
|
46
|
+
"import": {
|
|
47
|
+
"types": "./typings/*.d.ts",
|
|
48
|
+
"default": "./esm/*.js"
|
|
49
|
+
},
|
|
50
|
+
"default": {
|
|
51
|
+
"types": "./typings/*.d.ts",
|
|
52
|
+
"default": "./esm/*.js"
|
|
53
|
+
}
|
|
33
54
|
},
|
|
34
55
|
"./package.json": "./package.json"
|
|
35
56
|
}
|
|
36
|
-
}
|
|
57
|
+
}
|