@envelop/parser-cache 4.4.0-alpha-3936561.0 → 4.4.0-alpha-c0cc559.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,14 +1,9 @@
1
- import { Plugin } from '@envelop/core';
1
+ import { Plugin, BasicCache } from '@envelop/core';
2
2
  import { DocumentNode } from 'graphql';
3
- interface Cache<T> {
4
- get(key: string): T | undefined;
5
- set(key: string, value: T): void;
6
- }
7
- export declare type DocumentCache = Cache<DocumentNode>;
8
- export declare type ErrorCache = Cache<Error>;
3
+ export declare type DocumentCache = BasicCache<DocumentNode>;
4
+ export declare type ErrorCache = BasicCache<Error>;
9
5
  export declare type ParserCacheOptions = {
10
6
  documentCache?: DocumentCache;
11
7
  errorCache?: ErrorCache;
12
8
  };
13
9
  export declare const useParserCache: (pluginOptions?: ParserCacheOptions) => Plugin;
14
- export {};
package/index.js CHANGED
@@ -3,15 +3,15 @@
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
5
  const core = require('@envelop/core');
6
- const graphql = require('graphql');
7
6
 
8
7
  const useParserCache = (pluginOptions = {}) => {
9
- const documentCache = typeof pluginOptions.documentCache !== 'undefined' ? pluginOptions.documentCache : core.getInMemoryLRUCache();
10
- const errorCache = typeof pluginOptions.errorCache !== 'undefined' ? pluginOptions.errorCache : core.getInMemoryLRUCache();
8
+ const documentCache = pluginOptions.documentCache != null ? pluginOptions.documentCache : core.getInMemoryLRUCache();
9
+ const errorCache = pluginOptions.errorCache != null ? pluginOptions.errorCache : core.getInMemoryLRUCache();
11
10
  return {
12
11
  onParse({ params, setParsedDocument }) {
12
+ var _a;
13
13
  const { source } = params;
14
- const key = source instanceof graphql.Source ? source.body : source;
14
+ const key = core.isSourceObject(source) ? source.body : (_a = params.source) === null || _a === void 0 ? void 0 : _a.toString();
15
15
  const cachedError = errorCache.get(key);
16
16
  if (cachedError !== undefined) {
17
17
  throw cachedError;
@@ -19,12 +19,13 @@ const useParserCache = (pluginOptions = {}) => {
19
19
  const cachedDocument = documentCache.get(key);
20
20
  if (cachedDocument !== undefined) {
21
21
  setParsedDocument(cachedDocument);
22
+ return;
22
23
  }
23
24
  return ({ result }) => {
24
25
  if (result instanceof Error) {
25
26
  errorCache.set(key, result);
26
27
  }
27
- else if (result !== null) {
28
+ else if (result != null) {
28
29
  documentCache.set(key, result);
29
30
  }
30
31
  };
package/index.mjs CHANGED
@@ -1,13 +1,13 @@
1
- import { getInMemoryLRUCache } from '@envelop/core';
2
- import { Source } from 'graphql';
1
+ import { getInMemoryLRUCache, isSourceObject } from '@envelop/core';
3
2
 
4
3
  const useParserCache = (pluginOptions = {}) => {
5
- const documentCache = typeof pluginOptions.documentCache !== 'undefined' ? pluginOptions.documentCache : getInMemoryLRUCache();
6
- const errorCache = typeof pluginOptions.errorCache !== 'undefined' ? pluginOptions.errorCache : getInMemoryLRUCache();
4
+ const documentCache = pluginOptions.documentCache != null ? pluginOptions.documentCache : getInMemoryLRUCache();
5
+ const errorCache = pluginOptions.errorCache != null ? pluginOptions.errorCache : getInMemoryLRUCache();
7
6
  return {
8
7
  onParse({ params, setParsedDocument }) {
8
+ var _a;
9
9
  const { source } = params;
10
- const key = source instanceof Source ? source.body : source;
10
+ const key = isSourceObject(source) ? source.body : (_a = params.source) === null || _a === void 0 ? void 0 : _a.toString();
11
11
  const cachedError = errorCache.get(key);
12
12
  if (cachedError !== undefined) {
13
13
  throw cachedError;
@@ -15,12 +15,13 @@ const useParserCache = (pluginOptions = {}) => {
15
15
  const cachedDocument = documentCache.get(key);
16
16
  if (cachedDocument !== undefined) {
17
17
  setParsedDocument(cachedDocument);
18
+ return;
18
19
  }
19
20
  return ({ result }) => {
20
21
  if (result instanceof Error) {
21
22
  errorCache.set(key, result);
22
23
  }
23
- else if (result !== null) {
24
+ else if (result != null) {
24
25
  documentCache.set(key, result);
25
26
  }
26
27
  };
package/package.json CHANGED
@@ -1,9 +1,9 @@
1
1
  {
2
2
  "name": "@envelop/parser-cache",
3
- "version": "4.4.0-alpha-3936561.0",
3
+ "version": "4.4.0-alpha-c0cc559.0",
4
4
  "sideEffects": false,
5
5
  "peerDependencies": {
6
- "@envelop/core": "2.4.0-alpha-3936561.0",
6
+ "@envelop/core": "2.4.0-alpha-c0cc559.0",
7
7
  "graphql": "^14.0.0 || ^15.0.0 || ^16.0.0"
8
8
  },
9
9
  "repository": {