Skip to content

Commit cfde1e2

Browse files
committed
Lets go
1 parent b12dc17 commit cfde1e2

File tree

7 files changed

+23
-64
lines changed

7 files changed

+23
-64
lines changed

.changeset/social-camels-mate.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ Support polling in an interval by milliseconds
77

88
```yaml
99
plugins:
10-
- live-query:
10+
- liveQuery:
1111
invalidations:
1212
- pollingInterval: 10000 # Polling interval in milliseconds
1313
invalidate:

packages/legacy/types/src/config-schema.json

Lines changed: 6 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -2461,18 +2461,10 @@
24612461
"invalidations": {
24622462
"type": "array",
24632463
"items": {
2464-
"description": "Any of: LiveQueryInvalidationByMutation, LiveQueryInvalidationByPolling",
2465-
"anyOf": [
2466-
{
2467-
"$ref": "#/definitions/LiveQueryInvalidationByMutation"
2468-
},
2469-
{
2470-
"$ref": "#/definitions/LiveQueryInvalidationByPolling"
2471-
}
2472-
]
2464+
"$ref": "#/definitions/LiveQueryInvalidation"
24732465
},
24742466
"additionalItems": false,
2475-
"description": "Invalidate a query or queries when a specific operation is done without an error (Any of: LiveQueryInvalidationByMutation, LiveQueryInvalidationByPolling)"
2467+
"description": "Invalidate a query or queries when a specific operation is done without an error"
24762468
},
24772469
"resourceIdentifier": {
24782470
"type": "string",
@@ -2496,30 +2488,15 @@
24962488
}
24972489
}
24982490
},
2499-
"LiveQueryInvalidationByMutation": {
2491+
"LiveQueryInvalidation": {
25002492
"additionalProperties": false,
25012493
"type": "object",
2502-
"title": "LiveQueryInvalidationByMutation",
2494+
"title": "LiveQueryInvalidation",
25032495
"properties": {
25042496
"field": {
25052497
"type": "string",
25062498
"description": "Path to the operation that could effect it. In a form: Mutation.something. Note that wildcard is not supported in this field."
25072499
},
2508-
"invalidate": {
2509-
"type": "array",
2510-
"items": {
2511-
"type": "string"
2512-
},
2513-
"additionalItems": false
2514-
}
2515-
},
2516-
"required": ["field", "invalidate"]
2517-
},
2518-
"LiveQueryInvalidationByPolling": {
2519-
"additionalProperties": false,
2520-
"type": "object",
2521-
"title": "LiveQueryInvalidationByPolling",
2522-
"properties": {
25232500
"pollingInterval": {
25242501
"type": "integer",
25252502
"description": "Polling interval in milliseconds"
@@ -2529,11 +2506,10 @@
25292506
"items": {
25302507
"type": "string"
25312508
},
2532-
"additionalItems": false,
2533-
"description": "Schema coordinate of the query to be polled"
2509+
"additionalItems": false
25342510
}
25352511
},
2536-
"required": ["pollingInterval", "invalidate"]
2512+
"required": ["invalidate"]
25372513
},
25382514
"LiveQueryIndexBy": {
25392515
"additionalProperties": false,

packages/legacy/types/src/config.ts

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2153,9 +2153,9 @@ export interface HTTPDetailsExtensionsConfig {
21532153
}
21542154
export interface LiveQueryConfig {
21552155
/**
2156-
* Invalidate a query or queries when a specific operation is done without an error (Any of: LiveQueryInvalidationByMutation, LiveQueryInvalidationByPolling)
2156+
* Invalidate a query or queries when a specific operation is done without an error
21572157
*/
2158-
invalidations?: (LiveQueryInvalidationByMutation | LiveQueryInvalidationByPolling)[];
2158+
invalidations?: LiveQueryInvalidation[];
21592159
/**
21602160
* Custom strategy for building resources identifiers
21612161
* By default resource identifiers are built by concatenating the Typename with the id separated by a color (`User:1`).
@@ -2184,21 +2184,15 @@ export interface LiveQueryConfig {
21842184
*/
21852185
indexBy?: LiveQueryIndexBy[];
21862186
}
2187-
export interface LiveQueryInvalidationByMutation {
2187+
export interface LiveQueryInvalidation {
21882188
/**
21892189
* Path to the operation that could effect it. In a form: Mutation.something. Note that wildcard is not supported in this field.
21902190
*/
2191-
field: string;
2192-
invalidate: string[];
2193-
}
2194-
export interface LiveQueryInvalidationByPolling {
2191+
field?: string;
21952192
/**
21962193
* Polling interval in milliseconds
21972194
*/
2198-
pollingInterval: number;
2199-
/**
2200-
* Schema coordinate of the query to be polled
2201-
*/
2195+
pollingInterval?: number;
22022196
invalidate: string[];
22032197
}
22042198
export interface LiveQueryIndexBy {

packages/plugins/live-query/src/useInvalidateByResult.ts

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,9 @@ import {
1111
} from '@graphql-mesh/types';
1212
import { DisposableSymbols } from '@whatwg-node/disposablestack';
1313

14-
// Hybrid type that supports both polling and mutation-based invalidation
15-
type LiveQueryInvalidationHybrid = (
16-
| YamlConfig.LiveQueryInvalidationByMutation
17-
| YamlConfig.LiveQueryInvalidationByPolling
18-
) & Partial<YamlConfig.LiveQueryInvalidationByMutation> & Partial<YamlConfig.LiveQueryInvalidationByPolling>;
19-
2014
interface InvalidateByResultParams {
2115
pubsub: MeshPubSub | HivePubSub;
22-
invalidations: LiveQueryInvalidationHybrid[];
16+
invalidations: YamlConfig.LiveQueryInvalidation[];
2317
logger: Logger;
2418
}
2519

@@ -34,7 +28,7 @@ export function useInvalidateByResult(params: InvalidateByResultParams): Plugin
3428
);
3529

3630
// Set up polling-based invalidation if pollingInterval is provided
37-
if ('pollingInterval' in liveQueryInvalidation && liveQueryInvalidation.pollingInterval) {
31+
if (liveQueryInvalidation.pollingInterval != null) {
3832
timers.add(
3933
setInterval(() => {
4034
pubsub.publish('live-query:invalidate', liveQueryInvalidation.invalidate);
@@ -43,7 +37,7 @@ export function useInvalidateByResult(params: InvalidateByResultParams): Plugin
4337
}
4438

4539
// Set up mutation-based invalidation if field is provided
46-
if ('field' in liveQueryInvalidation && liveQueryInvalidation.field) {
40+
if (liveQueryInvalidation.field != null) {
4741
liveQueryInvalidationFactoryMap.set(liveQueryInvalidation.field, factories);
4842
}
4943
});

packages/plugins/live-query/yaml-config.graphql

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -38,24 +38,15 @@ type LiveQueryConfig {
3838
indexBy: [LiveQueryIndexBy]
3939
}
4040

41-
union LiveQueryInvalidation @md = LiveQueryInvalidationByMutation | LiveQueryInvalidationByPolling
42-
43-
type LiveQueryInvalidationByMutation @md {
41+
type LiveQueryInvalidation @md {
4442
"""
4543
Path to the operation that could effect it. In a form: Mutation.something. Note that wildcard is not supported in this field.
4644
"""
47-
field: String!
48-
invalidate: [String!]!
49-
}
50-
51-
type LiveQueryInvalidationByPolling @md {
45+
field: String
5246
"""
5347
Polling interval in milliseconds
5448
"""
55-
pollingInterval: Int!
56-
"""
57-
Schema coordinate of the query to be polled
58-
"""
49+
pollingInterval: Int
5950
invalidate: [String!]!
6051
}
6152

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
2+
* `field` (type: `String`) - Path to the operation that could effect it. In a form: Mutation.something. Note that wildcard is not supported in this field.
3+
* `pollingInterval` (type: `Int`) - Polling interval in milliseconds
4+
* `invalidate` (type: `Array of String`, required)

website/src/pages/docs/plugins/live-queries.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ query to be polled.
9999

100100
```yaml filename=".meshrc.yaml"
101101
plugins:
102-
- live-query:
102+
- liveQuery:
103103
invalidations:
104104
- pollingInterval: 10000 # Polling interval in milliseconds
105105
invalidate:

0 commit comments

Comments
 (0)