@graphql-mesh/plugin-deduplicate-request 1.0.0-alpha-20230424113259-560b18922 → 1.0.0-alpha-20230522110904-130abe0f9

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/cjs/index.js CHANGED
@@ -10,6 +10,7 @@ function useDeduplicateRequest() {
10
10
  }
11
11
  return reqResMap;
12
12
  }
13
+ const resPropMap = new WeakMap();
13
14
  return {
14
15
  onFetch({ url, options, context, info, fetchFn, setFetchFn }) {
15
16
  if (context != null) {
@@ -29,7 +30,28 @@ function useDeduplicateRequest() {
29
30
  dedupRes$ = fetchFn(url, options, context, info);
30
31
  reqResMap.set(dedupCacheKey, dedupRes$);
31
32
  }
32
- return dedupRes$;
33
+ return dedupRes$.then(res => {
34
+ let resPropMapByRes = resPropMap.get(res);
35
+ if (!resPropMapByRes) {
36
+ resPropMapByRes = new Map();
37
+ resPropMap.set(res, resPropMapByRes);
38
+ }
39
+ return new Proxy(res, {
40
+ get(target, prop) {
41
+ if (typeof target[prop] === 'function') {
42
+ return (...args) => {
43
+ let resPropResult$ = resPropMapByRes.get(prop);
44
+ if (!resPropResult$) {
45
+ resPropResult$ = target[prop](...args);
46
+ resPropMapByRes.set(prop, resPropResult$);
47
+ }
48
+ return resPropResult$;
49
+ };
50
+ }
51
+ return target[prop];
52
+ },
53
+ });
54
+ });
33
55
  });
34
56
  }
35
57
  }
package/esm/index.js CHANGED
@@ -8,6 +8,7 @@ export default function useDeduplicateRequest() {
8
8
  }
9
9
  return reqResMap;
10
10
  }
11
+ const resPropMap = new WeakMap();
11
12
  return {
12
13
  onFetch({ url, options, context, info, fetchFn, setFetchFn }) {
13
14
  if (context != null) {
@@ -27,7 +28,28 @@ export default function useDeduplicateRequest() {
27
28
  dedupRes$ = fetchFn(url, options, context, info);
28
29
  reqResMap.set(dedupCacheKey, dedupRes$);
29
30
  }
30
- return dedupRes$;
31
+ return dedupRes$.then(res => {
32
+ let resPropMapByRes = resPropMap.get(res);
33
+ if (!resPropMapByRes) {
34
+ resPropMapByRes = new Map();
35
+ resPropMap.set(res, resPropMapByRes);
36
+ }
37
+ return new Proxy(res, {
38
+ get(target, prop) {
39
+ if (typeof target[prop] === 'function') {
40
+ return (...args) => {
41
+ let resPropResult$ = resPropMapByRes.get(prop);
42
+ if (!resPropResult$) {
43
+ resPropResult$ = target[prop](...args);
44
+ resPropMapByRes.set(prop, resPropResult$);
45
+ }
46
+ return resPropResult$;
47
+ };
48
+ }
49
+ return target[prop];
50
+ },
51
+ });
52
+ });
31
53
  });
32
54
  }
33
55
  }
package/package.json CHANGED
@@ -1,10 +1,10 @@
1
1
  {
2
2
  "name": "@graphql-mesh/plugin-deduplicate-request",
3
- "version": "1.0.0-alpha-20230424113259-560b18922",
3
+ "version": "1.0.0-alpha-20230522110904-130abe0f9",
4
4
  "sideEffects": false,
5
5
  "peerDependencies": {
6
- "@graphql-mesh/types": "1.0.0-alpha-20230424113259-560b18922",
7
- "@graphql-mesh/utils": "1.0.0-alpha-20230424113259-560b18922",
6
+ "@graphql-mesh/types": "1.0.0-alpha-20230522110904-130abe0f9",
7
+ "@graphql-mesh/utils": "1.0.0-alpha-20230522110904-130abe0f9",
8
8
  "graphql": "*",
9
9
  "tslib": "^2.4.0"
10
10
  },