@envelop/validation-cache 4.4.0-alpha-3936561.0 → 4.4.0-alpha-0969daf.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,10 +1,8 @@
1
- import { Plugin } from '@envelop/core';
1
+ import { BasicCache, Plugin } from '@envelop/core';
2
2
  import { GraphQLError } from 'graphql';
3
- export interface ValidationCache {
4
- get(key: string): readonly GraphQLError[] | undefined;
5
- set(key: string, value: readonly GraphQLError[]): void;
3
+ export declare type ValidationCache = BasicCache<readonly GraphQLError[]> & {
6
4
  clear(): void;
7
- }
5
+ };
8
6
  export declare type ValidationCacheOptions = {
9
7
  cache?: ValidationCache;
10
8
  };
package/index.js CHANGED
@@ -5,22 +5,23 @@ Object.defineProperty(exports, '__esModule', { value: true });
5
5
  const core = require('@envelop/core');
6
6
  const graphql = require('graphql');
7
7
 
8
- const rawDocumentSymbol = Symbol('rawDocument');
8
+ const rawDocumentMap = new WeakMap();
9
9
  const useValidationCache = (pluginOptions = {}) => {
10
10
  const resultCache = typeof pluginOptions.cache !== 'undefined' ? pluginOptions.cache : core.getInMemoryLRUCache();
11
11
  return {
12
12
  onSchemaChange() {
13
13
  resultCache.clear();
14
14
  },
15
- onParse({ params, extendContext }) {
16
- extendContext({ [rawDocumentSymbol]: params.source.toString() });
15
+ onParse({ params, context }) {
16
+ rawDocumentMap.set(context, params.source.toString());
17
17
  },
18
18
  onValidate({ params, context, setResult }) {
19
19
  var _a;
20
- const key = (_a = context[rawDocumentSymbol]) !== null && _a !== void 0 ? _a : graphql.print(params.documentAST);
20
+ const key = (_a = rawDocumentMap.get(context)) !== null && _a !== void 0 ? _a : graphql.print(params.documentAST);
21
21
  const cachedResult = resultCache.get(key);
22
22
  if (cachedResult !== undefined) {
23
23
  setResult(cachedResult);
24
+ return;
24
25
  }
25
26
  return ({ result }) => {
26
27
  resultCache.set(key, result);
package/index.mjs CHANGED
@@ -1,22 +1,23 @@
1
1
  import { getInMemoryLRUCache } from '@envelop/core';
2
2
  import { print } from 'graphql';
3
3
 
4
- const rawDocumentSymbol = Symbol('rawDocument');
4
+ const rawDocumentMap = new WeakMap();
5
5
  const useValidationCache = (pluginOptions = {}) => {
6
6
  const resultCache = typeof pluginOptions.cache !== 'undefined' ? pluginOptions.cache : getInMemoryLRUCache();
7
7
  return {
8
8
  onSchemaChange() {
9
9
  resultCache.clear();
10
10
  },
11
- onParse({ params, extendContext }) {
12
- extendContext({ [rawDocumentSymbol]: params.source.toString() });
11
+ onParse({ params, context }) {
12
+ rawDocumentMap.set(context, params.source.toString());
13
13
  },
14
14
  onValidate({ params, context, setResult }) {
15
15
  var _a;
16
- const key = (_a = context[rawDocumentSymbol]) !== null && _a !== void 0 ? _a : print(params.documentAST);
16
+ const key = (_a = rawDocumentMap.get(context)) !== null && _a !== void 0 ? _a : print(params.documentAST);
17
17
  const cachedResult = resultCache.get(key);
18
18
  if (cachedResult !== undefined) {
19
19
  setResult(cachedResult);
20
+ return;
20
21
  }
21
22
  return ({ result }) => {
22
23
  resultCache.set(key, result);
package/package.json CHANGED
@@ -1,9 +1,9 @@
1
1
  {
2
2
  "name": "@envelop/validation-cache",
3
- "version": "4.4.0-alpha-3936561.0",
3
+ "version": "4.4.0-alpha-0969daf.0",
4
4
  "sideEffects": false,
5
5
  "peerDependencies": {
6
- "@envelop/core": "2.4.0-alpha-3936561.0",
6
+ "@envelop/core": "2.4.0-alpha-0969daf.0",
7
7
  "graphql": "^14.0.0 || ^15.0.0 || ^16.0.0"
8
8
  },
9
9
  "repository": {