@graphql-mesh/plugin-live-query 0.104.14 → 0.104.15-alpha-20251103000320-0eb10bb65fedaf33990c08ccc9ba69fe2dd6d6a5
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,46 @@ 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();
|
|
9
|
-
|
|
10
|
+
const timers = new Set();
|
|
11
|
+
const pubsub = (0, types_1.toMeshPubSub)(params.pubsub);
|
|
12
|
+
if (!pubsub) {
|
|
13
|
+
throw new Error(`Live Query plugin requires a pubsub instance.`);
|
|
14
|
+
}
|
|
15
|
+
for (const liveQueryInvalidation of params.invalidations) {
|
|
16
|
+
if (liveQueryInvalidation.invalidate.length === 0) {
|
|
17
|
+
params.logger.warn(`Invalidation paths are empty for live query invalidation config: ${JSON.stringify(liveQueryInvalidation)}. Skipping this invalidation config.`);
|
|
18
|
+
continue;
|
|
19
|
+
}
|
|
10
20
|
const rawInvalidationPaths = liveQueryInvalidation.invalidate;
|
|
11
21
|
const factories = rawInvalidationPaths.map(rawInvalidationPath => (0, string_interpolation_1.getInterpolatedStringFactory)(rawInvalidationPath));
|
|
12
|
-
|
|
22
|
+
// Set up polling-based invalidation if pollingInterval is provided
|
|
23
|
+
if (liveQueryInvalidation.pollingInterval != null) {
|
|
24
|
+
if (liveQueryInvalidation.pollingInterval <= 0) {
|
|
25
|
+
throw new Error(`Polling interval must be a positive integer. Received: ${liveQueryInvalidation.pollingInterval}`);
|
|
26
|
+
}
|
|
27
|
+
timers.add(setInterval(() => {
|
|
28
|
+
pubsub.publish('live-query:invalidate', liveQueryInvalidation.invalidate);
|
|
29
|
+
}, liveQueryInvalidation.pollingInterval));
|
|
30
|
+
}
|
|
31
|
+
// Set up mutation-based invalidation if field is provided
|
|
32
|
+
if (liveQueryInvalidation.field != null) {
|
|
33
|
+
let existingFactories = liveQueryInvalidationFactoryMap.get(liveQueryInvalidation.field);
|
|
34
|
+
if (!existingFactories) {
|
|
35
|
+
existingFactories = [];
|
|
36
|
+
liveQueryInvalidationFactoryMap.set(liveQueryInvalidation.field, existingFactories);
|
|
37
|
+
}
|
|
38
|
+
existingFactories.push(...factories);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
const id = pubsub.subscribe('destroy', () => {
|
|
42
|
+
for (const timer of timers) {
|
|
43
|
+
clearInterval(timer);
|
|
44
|
+
}
|
|
45
|
+
pubsub.unsubscribe(id);
|
|
13
46
|
});
|
|
14
|
-
const pubsub = (0, types_1.toMeshPubSub)(params.pubsub);
|
|
15
47
|
return {
|
|
16
48
|
onExecute() {
|
|
17
49
|
return {
|
|
@@ -44,5 +76,10 @@ function useInvalidateByResult(params) {
|
|
|
44
76
|
},
|
|
45
77
|
};
|
|
46
78
|
},
|
|
79
|
+
[disposablestack_1.DisposableSymbols.dispose]() {
|
|
80
|
+
for (const timer of timers) {
|
|
81
|
+
clearInterval(timer);
|
|
82
|
+
}
|
|
83
|
+
},
|
|
47
84
|
};
|
|
48
85
|
}
|
|
@@ -1,14 +1,46 @@
|
|
|
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();
|
|
6
|
-
|
|
7
|
+
const timers = new Set();
|
|
8
|
+
const pubsub = toMeshPubSub(params.pubsub);
|
|
9
|
+
if (!pubsub) {
|
|
10
|
+
throw new Error(`Live Query plugin requires a pubsub instance.`);
|
|
11
|
+
}
|
|
12
|
+
for (const liveQueryInvalidation of params.invalidations) {
|
|
13
|
+
if (liveQueryInvalidation.invalidate.length === 0) {
|
|
14
|
+
params.logger.warn(`Invalidation paths are empty for live query invalidation config: ${JSON.stringify(liveQueryInvalidation)}. Skipping this invalidation config.`);
|
|
15
|
+
continue;
|
|
16
|
+
}
|
|
7
17
|
const rawInvalidationPaths = liveQueryInvalidation.invalidate;
|
|
8
18
|
const factories = rawInvalidationPaths.map(rawInvalidationPath => getInterpolatedStringFactory(rawInvalidationPath));
|
|
9
|
-
|
|
19
|
+
// Set up polling-based invalidation if pollingInterval is provided
|
|
20
|
+
if (liveQueryInvalidation.pollingInterval != null) {
|
|
21
|
+
if (liveQueryInvalidation.pollingInterval <= 0) {
|
|
22
|
+
throw new Error(`Polling interval must be a positive integer. Received: ${liveQueryInvalidation.pollingInterval}`);
|
|
23
|
+
}
|
|
24
|
+
timers.add(setInterval(() => {
|
|
25
|
+
pubsub.publish('live-query:invalidate', liveQueryInvalidation.invalidate);
|
|
26
|
+
}, liveQueryInvalidation.pollingInterval));
|
|
27
|
+
}
|
|
28
|
+
// Set up mutation-based invalidation if field is provided
|
|
29
|
+
if (liveQueryInvalidation.field != null) {
|
|
30
|
+
let existingFactories = liveQueryInvalidationFactoryMap.get(liveQueryInvalidation.field);
|
|
31
|
+
if (!existingFactories) {
|
|
32
|
+
existingFactories = [];
|
|
33
|
+
liveQueryInvalidationFactoryMap.set(liveQueryInvalidation.field, existingFactories);
|
|
34
|
+
}
|
|
35
|
+
existingFactories.push(...factories);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
const id = pubsub.subscribe('destroy', () => {
|
|
39
|
+
for (const timer of timers) {
|
|
40
|
+
clearInterval(timer);
|
|
41
|
+
}
|
|
42
|
+
pubsub.unsubscribe(id);
|
|
10
43
|
});
|
|
11
|
-
const pubsub = toMeshPubSub(params.pubsub);
|
|
12
44
|
return {
|
|
13
45
|
onExecute() {
|
|
14
46
|
return {
|
|
@@ -41,5 +73,10 @@ export function useInvalidateByResult(params) {
|
|
|
41
73
|
},
|
|
42
74
|
};
|
|
43
75
|
},
|
|
76
|
+
[DisposableSymbols.dispose]() {
|
|
77
|
+
for (const timer of timers) {
|
|
78
|
+
clearInterval(timer);
|
|
79
|
+
}
|
|
80
|
+
},
|
|
44
81
|
};
|
|
45
82
|
}
|
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.15-alpha-20251103000320-0eb10bb65fedaf33990c08ccc9ba69fe2dd6d6a5",
|
|
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.15-alpha-20251103000320-0eb10bb65fedaf33990c08ccc9ba69fe2dd6d6a5",
|
|
14
|
+
"@graphql-mesh/utils": "0.104.15-alpha-20251103000320-0eb10bb65fedaf33990c08ccc9ba69fe2dd6d6a5",
|
|
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
5
|
invalidations: YamlConfig.LiveQueryInvalidation[];
|
|
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
5
|
invalidations: YamlConfig.LiveQueryInvalidation[];
|
|
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 {};
|