@graphql-mesh/plugin-live-query 0.104.14-alpha-20250922151901-2100ea6ff399fc0053cc422e3cc6ab17fe79be1c → 0.104.15-alpha-20251102235905-8ac0fd50987066e2ac7a0fe30cf561aa296b726b

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.
@@ -9,18 +9,35 @@ function useInvalidateByResult(params) {
9
9
  const liveQueryInvalidationFactoryMap = new Map();
10
10
  const timers = new Set();
11
11
  const pubsub = (0, types_1.toMeshPubSub)(params.pubsub);
12
- params.invalidations.forEach(liveQueryInvalidation => {
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
+ }
13
20
  const rawInvalidationPaths = liveQueryInvalidation.invalidate;
14
21
  const factories = rawInvalidationPaths.map(rawInvalidationPath => (0, string_interpolation_1.getInterpolatedStringFactory)(rawInvalidationPath));
15
- if ('pollingInterval' in liveQueryInvalidation) {
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
+ }
16
27
  timers.add(setInterval(() => {
17
28
  pubsub.publish('live-query:invalidate', liveQueryInvalidation.invalidate);
18
29
  }, liveQueryInvalidation.pollingInterval));
19
30
  }
20
- else if ('field' in liveQueryInvalidation) {
21
- liveQueryInvalidationFactoryMap.set(liveQueryInvalidation.field, factories);
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);
22
39
  }
23
- });
40
+ }
24
41
  const id = pubsub.subscribe('destroy', () => {
25
42
  for (const timer of timers) {
26
43
  clearInterval(timer);
@@ -6,18 +6,35 @@ export function useInvalidateByResult(params) {
6
6
  const liveQueryInvalidationFactoryMap = new Map();
7
7
  const timers = new Set();
8
8
  const pubsub = toMeshPubSub(params.pubsub);
9
- params.invalidations.forEach(liveQueryInvalidation => {
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
+ }
10
17
  const rawInvalidationPaths = liveQueryInvalidation.invalidate;
11
18
  const factories = rawInvalidationPaths.map(rawInvalidationPath => getInterpolatedStringFactory(rawInvalidationPath));
12
- if ('pollingInterval' in liveQueryInvalidation) {
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
+ }
13
24
  timers.add(setInterval(() => {
14
25
  pubsub.publish('live-query:invalidate', liveQueryInvalidation.invalidate);
15
26
  }, liveQueryInvalidation.pollingInterval));
16
27
  }
17
- else if ('field' in liveQueryInvalidation) {
18
- liveQueryInvalidationFactoryMap.set(liveQueryInvalidation.field, factories);
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);
19
36
  }
20
- });
37
+ }
21
38
  const id = pubsub.subscribe('destroy', () => {
22
39
  for (const timer of timers) {
23
40
  clearInterval(timer);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@graphql-mesh/plugin-live-query",
3
- "version": "0.104.14-alpha-20250922151901-2100ea6ff399fc0053cc422e3cc6ab17fe79be1c",
3
+ "version": "0.104.15-alpha-20251102235905-8ac0fd50987066e2ac7a0fe30cf561aa296b726b",
4
4
  "sideEffects": false,
5
5
  "peerDependencies": {
6
6
  "graphql": "*"
@@ -10,8 +10,8 @@
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": "0.104.14-alpha-20250922151901-2100ea6ff399fc0053cc422e3cc6ab17fe79be1c",
14
- "@graphql-mesh/utils": "0.104.14-alpha-20250922151901-2100ea6ff399fc0053cc422e3cc6ab17fe79be1c",
13
+ "@graphql-mesh/types": "0.104.15-alpha-20251102235905-8ac0fd50987066e2ac7a0fe30cf561aa296b726b",
14
+ "@graphql-mesh/utils": "0.104.15-alpha-20251102235905-8ac0fd50987066e2ac7a0fe30cf561aa296b726b",
15
15
  "@n1ru4l/in-memory-live-query-store": "^0.10.0",
16
16
  "@whatwg-node/disposablestack": "^0.0.6",
17
17
  "tslib": "^2.4.0"
@@ -2,7 +2,7 @@ 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.LiveQueryInvalidationByMutation | YamlConfig.LiveQueryInvalidationByPolling)[];
5
+ invalidations: YamlConfig.LiveQueryInvalidation[];
6
6
  logger: Logger;
7
7
  }
8
8
  export declare function useInvalidateByResult(params: InvalidateByResultParams): Plugin & Disposable;
@@ -2,7 +2,7 @@ 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.LiveQueryInvalidationByMutation | YamlConfig.LiveQueryInvalidationByPolling)[];
5
+ invalidations: YamlConfig.LiveQueryInvalidation[];
6
6
  logger: Logger;
7
7
  }
8
8
  export declare function useInvalidateByResult(params: InvalidateByResultParams): Plugin & Disposable;