@envelop/parser-cache 4.4.0-alpha-e9434aa.0 → 4.4.0-alpha-05dbec7.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/esm/index.js +6 -13
- package/package.json +2 -2
package/esm/index.js
CHANGED
|
@@ -1,22 +1,16 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.useParserCache = void 0;
|
|
7
|
-
const graphql_1 = require("graphql");
|
|
8
|
-
const tiny_lru_1 = __importDefault(require("tiny-lru"));
|
|
1
|
+
import { Source } from 'graphql';
|
|
2
|
+
import lru from 'tiny-lru';
|
|
9
3
|
const DEFAULT_MAX = 1000;
|
|
10
4
|
const DEFAULT_TTL = 3600000;
|
|
11
|
-
const useParserCache = (pluginOptions = {}) => {
|
|
5
|
+
export const useParserCache = (pluginOptions = {}) => {
|
|
12
6
|
const documentCache = typeof pluginOptions.documentCache !== 'undefined'
|
|
13
7
|
? pluginOptions.documentCache
|
|
14
|
-
: (
|
|
15
|
-
const errorCache = typeof pluginOptions.errorCache !== 'undefined' ? pluginOptions.errorCache : (
|
|
8
|
+
: lru(DEFAULT_MAX, DEFAULT_TTL);
|
|
9
|
+
const errorCache = typeof pluginOptions.errorCache !== 'undefined' ? pluginOptions.errorCache : lru(DEFAULT_MAX, DEFAULT_TTL);
|
|
16
10
|
return {
|
|
17
11
|
onParse({ params, setParsedDocument }) {
|
|
18
12
|
const { source } = params;
|
|
19
|
-
const key = source instanceof
|
|
13
|
+
const key = source instanceof Source ? source.body : source;
|
|
20
14
|
const cachedError = errorCache.get(key);
|
|
21
15
|
if (cachedError !== undefined) {
|
|
22
16
|
throw cachedError;
|
|
@@ -36,4 +30,3 @@ const useParserCache = (pluginOptions = {}) => {
|
|
|
36
30
|
},
|
|
37
31
|
};
|
|
38
32
|
};
|
|
39
|
-
exports.useParserCache = useParserCache;
|
package/package.json
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@envelop/parser-cache",
|
|
3
|
-
"version": "4.4.0-alpha-
|
|
3
|
+
"version": "4.4.0-alpha-05dbec7.0",
|
|
4
4
|
"sideEffects": false,
|
|
5
5
|
"peerDependencies": {
|
|
6
|
-
"@envelop/core": "2.4.0-alpha-
|
|
6
|
+
"@envelop/core": "2.4.0-alpha-05dbec7.0",
|
|
7
7
|
"graphql": "^14.0.0 || ^15.0.0 || ^16.0.0"
|
|
8
8
|
},
|
|
9
9
|
"dependencies": {
|