@envelop/validation-cache 2.1.0 → 2.3.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.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { Plugin } from '@envelop/types';
1
+ import { Plugin } from '@envelop/core';
2
2
  import { GraphQLError } from 'graphql';
3
3
  export interface ValidationCache {
4
4
  get(key: string): readonly GraphQLError[] | undefined;
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
- onValidate({ params, setResult }) {
19
- const key = graphql.print(params.documentAST);
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
- onValidate({ params, setResult }) {
13
- const key = print(params.documentAST);
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,8 +1,9 @@
1
1
  {
2
2
  "name": "@envelop/validation-cache",
3
- "version": "2.1.0",
3
+ "version": "2.3.0",
4
4
  "sideEffects": false,
5
5
  "peerDependencies": {
6
+ "@envelop/core": "^1.6.1",
6
7
  "graphql": "^14.0.0 || ^15.0.0 || ^16.0.0"
7
8
  },
8
9
  "dependencies": {
@@ -29,6 +30,7 @@
29
30
  "./*": {
30
31
  "require": "./*.js",
31
32
  "import": "./*.mjs"
32
- }
33
+ },
34
+ "./package.json": "./package.json"
33
35
  }
34
36
  }