@envelop/validation-cache 5.0.0-alpha-a07c198b.0 → 5.0.0-alpha-20220907122327-16ffa5de

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 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("@graphql-tools/graphql");
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
- (_a = resultCache.reset) === null || _a === void 0 ? void 0 : _a.call(resultCache);
20
+ resultCache.reset?.();
22
21
  }
23
22
  else if ('clear' in resultCache) {
24
- (_b = resultCache.clear) === null || _b === void 0 ? void 0 : _b.call(resultCache);
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
- var _a;
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 '@graphql-tools/graphql';
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
- (_a = resultCache.reset) === null || _a === void 0 ? void 0 : _a.call(resultCache);
16
+ resultCache.reset?.();
18
17
  }
19
18
  else if ('clear' in resultCache) {
20
- (_b = resultCache.clear) === null || _b === void 0 ? void 0 : _b.call(resultCache);
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
- var _a;
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-a07c198b.0",
3
+ "version": "5.0.0-alpha-20220907122327-16ffa5de",
4
4
  "sideEffects": false,
5
5
  "peerDependencies": {
6
- "@envelop/core": "3.0.0-alpha-a07c198b.0",
7
- "@graphql-tools/graphql": "0.1.0-alpha-20220809192840-c5b336bd"
6
+ "@envelop/core": "3.0.0-alpha-20220907122327-16ffa5de",
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",
@@ -1,5 +1,5 @@
1
1
  import { Plugin } from '@envelop/core';
2
- import { GraphQLError } from '@graphql-tools/graphql';
2
+ import { GraphQLError } from 'graphql';
3
3
  export interface ValidationCache {
4
4
  /**
5
5
  * Get a result from the validation cache.
@@ -1,5 +1,5 @@
1
1
  import { Plugin } from '@envelop/core';
2
- import { GraphQLError } from '@graphql-tools/graphql';
2
+ import { GraphQLError } from 'graphql';
3
3
  export interface ValidationCache {
4
4
  /**
5
5
  * Get a result from the validation cache.