@graphql-mesh/plugin-live-query 0.104.13 → 0.104.14-alpha-20250922151901-2100ea6ff399fc0053cc422e3cc6ab17fe79be1c
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.
|
@@ -4,14 +4,29 @@ exports.useInvalidateByResult = useInvalidateByResult;
|
|
|
4
4
|
const graphql_1 = require("graphql");
|
|
5
5
|
const string_interpolation_1 = require("@graphql-mesh/string-interpolation");
|
|
6
6
|
const types_1 = require("@graphql-mesh/types");
|
|
7
|
+
const disposablestack_1 = require("@whatwg-node/disposablestack");
|
|
7
8
|
function useInvalidateByResult(params) {
|
|
8
9
|
const liveQueryInvalidationFactoryMap = new Map();
|
|
10
|
+
const timers = new Set();
|
|
11
|
+
const pubsub = (0, types_1.toMeshPubSub)(params.pubsub);
|
|
9
12
|
params.invalidations.forEach(liveQueryInvalidation => {
|
|
10
13
|
const rawInvalidationPaths = liveQueryInvalidation.invalidate;
|
|
11
14
|
const factories = rawInvalidationPaths.map(rawInvalidationPath => (0, string_interpolation_1.getInterpolatedStringFactory)(rawInvalidationPath));
|
|
12
|
-
|
|
15
|
+
if ('pollingInterval' in liveQueryInvalidation) {
|
|
16
|
+
timers.add(setInterval(() => {
|
|
17
|
+
pubsub.publish('live-query:invalidate', liveQueryInvalidation.invalidate);
|
|
18
|
+
}, liveQueryInvalidation.pollingInterval));
|
|
19
|
+
}
|
|
20
|
+
else if ('field' in liveQueryInvalidation) {
|
|
21
|
+
liveQueryInvalidationFactoryMap.set(liveQueryInvalidation.field, factories);
|
|
22
|
+
}
|
|
23
|
+
});
|
|
24
|
+
const id = pubsub.subscribe('destroy', () => {
|
|
25
|
+
for (const timer of timers) {
|
|
26
|
+
clearInterval(timer);
|
|
27
|
+
}
|
|
28
|
+
pubsub.unsubscribe(id);
|
|
13
29
|
});
|
|
14
|
-
const pubsub = (0, types_1.toMeshPubSub)(params.pubsub);
|
|
15
30
|
return {
|
|
16
31
|
onExecute() {
|
|
17
32
|
return {
|
|
@@ -44,5 +59,10 @@ function useInvalidateByResult(params) {
|
|
|
44
59
|
},
|
|
45
60
|
};
|
|
46
61
|
},
|
|
62
|
+
[disposablestack_1.DisposableSymbols.dispose]() {
|
|
63
|
+
for (const timer of timers) {
|
|
64
|
+
clearInterval(timer);
|
|
65
|
+
}
|
|
66
|
+
},
|
|
47
67
|
};
|
|
48
68
|
}
|
|
@@ -1,14 +1,29 @@
|
|
|
1
1
|
import { getArgumentValues, getOperationAST, TypeInfo, visit, visitWithTypeInfo } from 'graphql';
|
|
2
2
|
import { getInterpolatedStringFactory } from '@graphql-mesh/string-interpolation';
|
|
3
3
|
import { toMeshPubSub, } from '@graphql-mesh/types';
|
|
4
|
+
import { DisposableSymbols } from '@whatwg-node/disposablestack';
|
|
4
5
|
export function useInvalidateByResult(params) {
|
|
5
6
|
const liveQueryInvalidationFactoryMap = new Map();
|
|
7
|
+
const timers = new Set();
|
|
8
|
+
const pubsub = toMeshPubSub(params.pubsub);
|
|
6
9
|
params.invalidations.forEach(liveQueryInvalidation => {
|
|
7
10
|
const rawInvalidationPaths = liveQueryInvalidation.invalidate;
|
|
8
11
|
const factories = rawInvalidationPaths.map(rawInvalidationPath => getInterpolatedStringFactory(rawInvalidationPath));
|
|
9
|
-
|
|
12
|
+
if ('pollingInterval' in liveQueryInvalidation) {
|
|
13
|
+
timers.add(setInterval(() => {
|
|
14
|
+
pubsub.publish('live-query:invalidate', liveQueryInvalidation.invalidate);
|
|
15
|
+
}, liveQueryInvalidation.pollingInterval));
|
|
16
|
+
}
|
|
17
|
+
else if ('field' in liveQueryInvalidation) {
|
|
18
|
+
liveQueryInvalidationFactoryMap.set(liveQueryInvalidation.field, factories);
|
|
19
|
+
}
|
|
20
|
+
});
|
|
21
|
+
const id = pubsub.subscribe('destroy', () => {
|
|
22
|
+
for (const timer of timers) {
|
|
23
|
+
clearInterval(timer);
|
|
24
|
+
}
|
|
25
|
+
pubsub.unsubscribe(id);
|
|
10
26
|
});
|
|
11
|
-
const pubsub = toMeshPubSub(params.pubsub);
|
|
12
27
|
return {
|
|
13
28
|
onExecute() {
|
|
14
29
|
return {
|
|
@@ -41,5 +56,10 @@ export function useInvalidateByResult(params) {
|
|
|
41
56
|
},
|
|
42
57
|
};
|
|
43
58
|
},
|
|
59
|
+
[DisposableSymbols.dispose]() {
|
|
60
|
+
for (const timer of timers) {
|
|
61
|
+
clearInterval(timer);
|
|
62
|
+
}
|
|
63
|
+
},
|
|
44
64
|
};
|
|
45
65
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@graphql-mesh/plugin-live-query",
|
|
3
|
-
"version": "0.104.
|
|
3
|
+
"version": "0.104.14-alpha-20250922151901-2100ea6ff399fc0053cc422e3cc6ab17fe79be1c",
|
|
4
4
|
"sideEffects": false,
|
|
5
5
|
"peerDependencies": {
|
|
6
6
|
"graphql": "*"
|
|
@@ -10,9 +10,10 @@
|
|
|
10
10
|
"@envelop/live-query": "^9.0.0",
|
|
11
11
|
"@graphql-mesh/cross-helpers": "^0.4.10",
|
|
12
12
|
"@graphql-mesh/string-interpolation": "^0.5.9",
|
|
13
|
-
"@graphql-mesh/types": "
|
|
14
|
-
"@graphql-mesh/utils": "
|
|
13
|
+
"@graphql-mesh/types": "0.104.14-alpha-20250922151901-2100ea6ff399fc0053cc422e3cc6ab17fe79be1c",
|
|
14
|
+
"@graphql-mesh/utils": "0.104.14-alpha-20250922151901-2100ea6ff399fc0053cc422e3cc6ab17fe79be1c",
|
|
15
15
|
"@n1ru4l/in-memory-live-query-store": "^0.10.0",
|
|
16
|
+
"@whatwg-node/disposablestack": "^0.0.6",
|
|
16
17
|
"tslib": "^2.4.0"
|
|
17
18
|
},
|
|
18
19
|
"repository": {
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import { type Plugin } from '@envelop/core';
|
|
2
2
|
import { type HivePubSub, type Logger, type MeshPubSub, type YamlConfig } from '@graphql-mesh/types';
|
|
3
3
|
interface InvalidateByResultParams {
|
|
4
4
|
pubsub: MeshPubSub | HivePubSub;
|
|
5
|
-
invalidations: YamlConfig.
|
|
5
|
+
invalidations: (YamlConfig.LiveQueryInvalidationByMutation | YamlConfig.LiveQueryInvalidationByPolling)[];
|
|
6
6
|
logger: Logger;
|
|
7
7
|
}
|
|
8
|
-
export declare function useInvalidateByResult(params: InvalidateByResultParams): Plugin;
|
|
8
|
+
export declare function useInvalidateByResult(params: InvalidateByResultParams): Plugin & Disposable;
|
|
9
9
|
export {};
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import { type Plugin } from '@envelop/core';
|
|
2
2
|
import { type HivePubSub, type Logger, type MeshPubSub, type YamlConfig } from '@graphql-mesh/types';
|
|
3
3
|
interface InvalidateByResultParams {
|
|
4
4
|
pubsub: MeshPubSub | HivePubSub;
|
|
5
|
-
invalidations: YamlConfig.
|
|
5
|
+
invalidations: (YamlConfig.LiveQueryInvalidationByMutation | YamlConfig.LiveQueryInvalidationByPolling)[];
|
|
6
6
|
logger: Logger;
|
|
7
7
|
}
|
|
8
|
-
export declare function useInvalidateByResult(params: InvalidateByResultParams): Plugin;
|
|
8
|
+
export declare function useInvalidateByResult(params: InvalidateByResultParams): Plugin & Disposable;
|
|
9
9
|
export {};
|