@graphql-mesh/plugin-live-query 1.0.0-alpha-3fc47d119.0 → 1.0.0-alpha-20230420181317-a95037648
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 +41 -0
- package/cjs/package.json +1 -0
- package/cjs/useInvalidateByResult.js +47 -0
- package/esm/index.js +38 -0
- package/esm/useInvalidateByResult.js +43 -0
- package/package.json +27 -20
- package/typings/index.d.cts +3 -0
- package/typings/useInvalidateByResult.d.cts +9 -0
- package/{useInvalidateByResult.d.ts → typings/useInvalidateByResult.d.ts} +2 -3
- package/index.js +0 -80
- package/index.mjs +0 -78
- package/{index.d.ts → typings/index.d.ts} +1 -1
package/cjs/index.js
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const live_query_1 = require("@envelop/live-query");
|
|
4
|
+
const cross_helpers_1 = require("@graphql-mesh/cross-helpers");
|
|
5
|
+
const string_interpolation_1 = require("@graphql-mesh/string-interpolation");
|
|
6
|
+
const in_memory_live_query_store_1 = require("@n1ru4l/in-memory-live-query-store");
|
|
7
|
+
const useInvalidateByResult_js_1 = require("./useInvalidateByResult.js");
|
|
8
|
+
function useMeshLiveQuery(options) {
|
|
9
|
+
options.logger.debug(`Creating Live Query Store`);
|
|
10
|
+
const liveQueryStore = new in_memory_live_query_store_1.InMemoryLiveQueryStore({
|
|
11
|
+
buildResourceIdentifier: options.resourceIdentifier != null
|
|
12
|
+
? function resourceIdentifierFactory({ typename, id }) {
|
|
13
|
+
return string_interpolation_1.stringInterpolator.parse(options.resourceIdentifier, {
|
|
14
|
+
typename,
|
|
15
|
+
id,
|
|
16
|
+
env: cross_helpers_1.process.env,
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
: in_memory_live_query_store_1.defaultResourceIdentifierNormalizer,
|
|
20
|
+
includeIdentifierExtension: options.includeIdentifierExtension != null
|
|
21
|
+
? options.includeIdentifierExtension
|
|
22
|
+
: cross_helpers_1.process.env.DEBUG === '1',
|
|
23
|
+
idFieldName: options.idFieldName,
|
|
24
|
+
indexBy: options.indexBy,
|
|
25
|
+
});
|
|
26
|
+
options.pubsub.subscribe('live-query:invalidate', (identifiers) => liveQueryStore.invalidate(identifiers));
|
|
27
|
+
return {
|
|
28
|
+
onPluginInit({ addPlugin }) {
|
|
29
|
+
var _a;
|
|
30
|
+
addPlugin((0, live_query_1.useLiveQuery)({ liveQueryStore }));
|
|
31
|
+
if ((_a = options.invalidations) === null || _a === void 0 ? void 0 : _a.length) {
|
|
32
|
+
addPlugin((0, useInvalidateByResult_js_1.useInvalidateByResult)({
|
|
33
|
+
pubsub: options.pubsub,
|
|
34
|
+
invalidations: options.invalidations,
|
|
35
|
+
logger: options.logger,
|
|
36
|
+
}));
|
|
37
|
+
}
|
|
38
|
+
},
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
exports.default = useMeshLiveQuery;
|
package/cjs/package.json
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"type":"commonjs"}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.useInvalidateByResult = void 0;
|
|
4
|
+
const graphql_1 = require("graphql");
|
|
5
|
+
const string_interpolation_1 = require("@graphql-mesh/string-interpolation");
|
|
6
|
+
function useInvalidateByResult(params) {
|
|
7
|
+
const liveQueryInvalidationFactoryMap = new Map();
|
|
8
|
+
params.invalidations.forEach(liveQueryInvalidation => {
|
|
9
|
+
const rawInvalidationPaths = liveQueryInvalidation.invalidate;
|
|
10
|
+
const factories = rawInvalidationPaths.map(rawInvalidationPath => (0, string_interpolation_1.getInterpolatedStringFactory)(rawInvalidationPath));
|
|
11
|
+
liveQueryInvalidationFactoryMap.set(liveQueryInvalidation.field, factories);
|
|
12
|
+
});
|
|
13
|
+
return {
|
|
14
|
+
onExecute() {
|
|
15
|
+
return {
|
|
16
|
+
onExecuteDone({ args: executionArgs, result }) {
|
|
17
|
+
const { schema, document, operationName, variableValues, rootValue, contextValue } = executionArgs;
|
|
18
|
+
const operationAST = (0, graphql_1.getOperationAST)(document, operationName);
|
|
19
|
+
if (!operationAST) {
|
|
20
|
+
throw new Error(`Operation couldn't be found`);
|
|
21
|
+
}
|
|
22
|
+
const typeInfo = new graphql_1.TypeInfo(schema);
|
|
23
|
+
(0, graphql_1.visit)(operationAST, (0, graphql_1.visitWithTypeInfo)(typeInfo, {
|
|
24
|
+
Field: fieldNode => {
|
|
25
|
+
const parentType = typeInfo.getParentType();
|
|
26
|
+
const fieldDef = typeInfo.getFieldDef();
|
|
27
|
+
const path = `${parentType.name}.${fieldDef.name}`;
|
|
28
|
+
if (liveQueryInvalidationFactoryMap.has(path)) {
|
|
29
|
+
const invalidationPathFactories = liveQueryInvalidationFactoryMap.get(path);
|
|
30
|
+
const args = (0, graphql_1.getArgumentValues)(fieldDef, fieldNode, variableValues);
|
|
31
|
+
const invalidationPaths = invalidationPathFactories.map(invalidationPathFactory => invalidationPathFactory({
|
|
32
|
+
root: rootValue,
|
|
33
|
+
args,
|
|
34
|
+
context: contextValue,
|
|
35
|
+
env: process.env,
|
|
36
|
+
result,
|
|
37
|
+
}));
|
|
38
|
+
params.pubsub.publish('live-query:invalidate', invalidationPaths);
|
|
39
|
+
}
|
|
40
|
+
},
|
|
41
|
+
}));
|
|
42
|
+
},
|
|
43
|
+
};
|
|
44
|
+
},
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
exports.useInvalidateByResult = useInvalidateByResult;
|
package/esm/index.js
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { useLiveQuery } from '@envelop/live-query';
|
|
2
|
+
import { process } from '@graphql-mesh/cross-helpers';
|
|
3
|
+
import { stringInterpolator } from '@graphql-mesh/string-interpolation';
|
|
4
|
+
import { defaultResourceIdentifierNormalizer, InMemoryLiveQueryStore, } from '@n1ru4l/in-memory-live-query-store';
|
|
5
|
+
import { useInvalidateByResult } from './useInvalidateByResult.js';
|
|
6
|
+
export default function useMeshLiveQuery(options) {
|
|
7
|
+
options.logger.debug(`Creating Live Query Store`);
|
|
8
|
+
const liveQueryStore = new InMemoryLiveQueryStore({
|
|
9
|
+
buildResourceIdentifier: options.resourceIdentifier != null
|
|
10
|
+
? function resourceIdentifierFactory({ typename, id }) {
|
|
11
|
+
return stringInterpolator.parse(options.resourceIdentifier, {
|
|
12
|
+
typename,
|
|
13
|
+
id,
|
|
14
|
+
env: process.env,
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
: defaultResourceIdentifierNormalizer,
|
|
18
|
+
includeIdentifierExtension: options.includeIdentifierExtension != null
|
|
19
|
+
? options.includeIdentifierExtension
|
|
20
|
+
: process.env.DEBUG === '1',
|
|
21
|
+
idFieldName: options.idFieldName,
|
|
22
|
+
indexBy: options.indexBy,
|
|
23
|
+
});
|
|
24
|
+
options.pubsub.subscribe('live-query:invalidate', (identifiers) => liveQueryStore.invalidate(identifiers));
|
|
25
|
+
return {
|
|
26
|
+
onPluginInit({ addPlugin }) {
|
|
27
|
+
var _a;
|
|
28
|
+
addPlugin(useLiveQuery({ liveQueryStore }));
|
|
29
|
+
if ((_a = options.invalidations) === null || _a === void 0 ? void 0 : _a.length) {
|
|
30
|
+
addPlugin(useInvalidateByResult({
|
|
31
|
+
pubsub: options.pubsub,
|
|
32
|
+
invalidations: options.invalidations,
|
|
33
|
+
logger: options.logger,
|
|
34
|
+
}));
|
|
35
|
+
}
|
|
36
|
+
},
|
|
37
|
+
};
|
|
38
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { getArgumentValues, getOperationAST, TypeInfo, visit, visitWithTypeInfo } from 'graphql';
|
|
2
|
+
import { getInterpolatedStringFactory, } from '@graphql-mesh/string-interpolation';
|
|
3
|
+
export function useInvalidateByResult(params) {
|
|
4
|
+
const liveQueryInvalidationFactoryMap = new Map();
|
|
5
|
+
params.invalidations.forEach(liveQueryInvalidation => {
|
|
6
|
+
const rawInvalidationPaths = liveQueryInvalidation.invalidate;
|
|
7
|
+
const factories = rawInvalidationPaths.map(rawInvalidationPath => getInterpolatedStringFactory(rawInvalidationPath));
|
|
8
|
+
liveQueryInvalidationFactoryMap.set(liveQueryInvalidation.field, factories);
|
|
9
|
+
});
|
|
10
|
+
return {
|
|
11
|
+
onExecute() {
|
|
12
|
+
return {
|
|
13
|
+
onExecuteDone({ args: executionArgs, result }) {
|
|
14
|
+
const { schema, document, operationName, variableValues, rootValue, contextValue } = executionArgs;
|
|
15
|
+
const operationAST = getOperationAST(document, operationName);
|
|
16
|
+
if (!operationAST) {
|
|
17
|
+
throw new Error(`Operation couldn't be found`);
|
|
18
|
+
}
|
|
19
|
+
const typeInfo = new TypeInfo(schema);
|
|
20
|
+
visit(operationAST, visitWithTypeInfo(typeInfo, {
|
|
21
|
+
Field: fieldNode => {
|
|
22
|
+
const parentType = typeInfo.getParentType();
|
|
23
|
+
const fieldDef = typeInfo.getFieldDef();
|
|
24
|
+
const path = `${parentType.name}.${fieldDef.name}`;
|
|
25
|
+
if (liveQueryInvalidationFactoryMap.has(path)) {
|
|
26
|
+
const invalidationPathFactories = liveQueryInvalidationFactoryMap.get(path);
|
|
27
|
+
const args = getArgumentValues(fieldDef, fieldNode, variableValues);
|
|
28
|
+
const invalidationPaths = invalidationPathFactories.map(invalidationPathFactory => invalidationPathFactory({
|
|
29
|
+
root: rootValue,
|
|
30
|
+
args,
|
|
31
|
+
context: contextValue,
|
|
32
|
+
env: process.env,
|
|
33
|
+
result,
|
|
34
|
+
}));
|
|
35
|
+
params.pubsub.publish('live-query:invalidate', invalidationPaths);
|
|
36
|
+
}
|
|
37
|
+
},
|
|
38
|
+
}));
|
|
39
|
+
},
|
|
40
|
+
};
|
|
41
|
+
},
|
|
42
|
+
};
|
|
43
|
+
}
|
package/package.json
CHANGED
|
@@ -1,18 +1,18 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@graphql-mesh/plugin-live-query",
|
|
3
|
-
"version": "1.0.0-alpha-
|
|
3
|
+
"version": "1.0.0-alpha-20230420181317-a95037648",
|
|
4
4
|
"sideEffects": false,
|
|
5
5
|
"peerDependencies": {
|
|
6
|
-
"@graphql-mesh/
|
|
7
|
-
"graphql": "
|
|
6
|
+
"@graphql-mesh/cross-helpers": "^0.3.4",
|
|
7
|
+
"@graphql-mesh/types": "1.0.0-alpha-20230420181317-a95037648",
|
|
8
|
+
"graphql": "*",
|
|
9
|
+
"tslib": "^2.4.0"
|
|
8
10
|
},
|
|
9
11
|
"dependencies": {
|
|
10
|
-
"@envelop/core": "^
|
|
11
|
-
"@envelop/live-query": "
|
|
12
|
-
"@graphql-mesh/
|
|
13
|
-
"@
|
|
14
|
-
"@n1ru4l/in-memory-live-query-store": "0.9.0",
|
|
15
|
-
"tslib": "^2.4.0"
|
|
12
|
+
"@envelop/core": "^3.0.0",
|
|
13
|
+
"@envelop/live-query": "5.0.6",
|
|
14
|
+
"@graphql-mesh/string-interpolation": "0.4.4",
|
|
15
|
+
"@n1ru4l/in-memory-live-query-store": "0.10.0"
|
|
16
16
|
},
|
|
17
17
|
"repository": {
|
|
18
18
|
"type": "git",
|
|
@@ -20,21 +20,28 @@
|
|
|
20
20
|
"directory": "packages/plugins/live-query"
|
|
21
21
|
},
|
|
22
22
|
"license": "MIT",
|
|
23
|
-
"main": "index.js",
|
|
24
|
-
"module": "index.
|
|
25
|
-
"typings": "index.d.ts",
|
|
23
|
+
"main": "cjs/index.js",
|
|
24
|
+
"module": "esm/index.js",
|
|
25
|
+
"typings": "typings/index.d.ts",
|
|
26
26
|
"typescript": {
|
|
27
|
-
"definition": "index.d.ts"
|
|
27
|
+
"definition": "typings/index.d.ts"
|
|
28
28
|
},
|
|
29
|
+
"type": "module",
|
|
29
30
|
"exports": {
|
|
30
31
|
".": {
|
|
31
|
-
"require":
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
"
|
|
36
|
-
|
|
32
|
+
"require": {
|
|
33
|
+
"types": "./typings/index.d.cts",
|
|
34
|
+
"default": "./cjs/index.js"
|
|
35
|
+
},
|
|
36
|
+
"import": {
|
|
37
|
+
"types": "./typings/index.d.ts",
|
|
38
|
+
"default": "./esm/index.js"
|
|
39
|
+
},
|
|
40
|
+
"default": {
|
|
41
|
+
"types": "./typings/index.d.ts",
|
|
42
|
+
"default": "./esm/index.js"
|
|
43
|
+
}
|
|
37
44
|
},
|
|
38
45
|
"./package.json": "./package.json"
|
|
39
46
|
}
|
|
40
|
-
}
|
|
47
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { Plugin } from '@envelop/core';
|
|
2
|
+
import { Logger, MeshPubSub, YamlConfig } from '@graphql-mesh/types';
|
|
3
|
+
interface InvalidateByResultParams {
|
|
4
|
+
pubsub: MeshPubSub;
|
|
5
|
+
invalidations: YamlConfig.LiveQueryInvalidation[];
|
|
6
|
+
logger: Logger;
|
|
7
|
+
}
|
|
8
|
+
export declare function useInvalidateByResult(params: InvalidateByResultParams): Plugin;
|
|
9
|
+
export {};
|
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
import { Plugin } from '@envelop/core';
|
|
2
|
-
import { Logger, YamlConfig } from '@graphql-mesh/types';
|
|
3
|
-
import { InMemoryLiveQueryStore } from '@n1ru4l/in-memory-live-query-store';
|
|
2
|
+
import { Logger, MeshPubSub, YamlConfig } from '@graphql-mesh/types';
|
|
4
3
|
interface InvalidateByResultParams {
|
|
5
|
-
|
|
4
|
+
pubsub: MeshPubSub;
|
|
6
5
|
invalidations: YamlConfig.LiveQueryInvalidation[];
|
|
7
6
|
logger: Logger;
|
|
8
7
|
}
|
package/index.js
DELETED
|
@@ -1,80 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
const liveQuery = require('@envelop/live-query');
|
|
4
|
-
const inMemoryLiveQueryStore = require('@n1ru4l/in-memory-live-query-store');
|
|
5
|
-
const stringInterpolation = require('@graphql-mesh/string-interpolation');
|
|
6
|
-
const graphql = require('graphql');
|
|
7
|
-
|
|
8
|
-
function useInvalidateByResult(params) {
|
|
9
|
-
const liveQueryInvalidationFactoryMap = new Map();
|
|
10
|
-
params.invalidations.forEach(liveQueryInvalidation => {
|
|
11
|
-
const rawInvalidationPaths = liveQueryInvalidation.invalidate;
|
|
12
|
-
const factories = rawInvalidationPaths.map(rawInvalidationPath => stringInterpolation.getInterpolatedStringFactory(rawInvalidationPath));
|
|
13
|
-
liveQueryInvalidationFactoryMap.set(liveQueryInvalidation.field, factories);
|
|
14
|
-
});
|
|
15
|
-
return {
|
|
16
|
-
onExecute() {
|
|
17
|
-
return {
|
|
18
|
-
onExecuteDone({ args: executionArgs, result }) {
|
|
19
|
-
queueMicrotask(() => {
|
|
20
|
-
const { schema, document, operationName, rootValue, contextValue } = executionArgs;
|
|
21
|
-
const operationAST = graphql.getOperationAST(document, operationName);
|
|
22
|
-
if (!operationAST) {
|
|
23
|
-
throw new Error(`Operation couldn't be found`);
|
|
24
|
-
}
|
|
25
|
-
const typeInfo = new graphql.TypeInfo(schema);
|
|
26
|
-
graphql.visit(operationAST, graphql.visitWithTypeInfo(typeInfo, {
|
|
27
|
-
Field: () => {
|
|
28
|
-
const parentType = typeInfo.getParentType();
|
|
29
|
-
const fieldDef = typeInfo.getFieldDef();
|
|
30
|
-
const path = `${parentType.name}.${fieldDef.name}`;
|
|
31
|
-
if (liveQueryInvalidationFactoryMap.has(path)) {
|
|
32
|
-
const invalidationPathFactories = liveQueryInvalidationFactoryMap.get(path);
|
|
33
|
-
const invalidationPaths = invalidationPathFactories.map(invalidationPathFactory => invalidationPathFactory({
|
|
34
|
-
root: rootValue,
|
|
35
|
-
context: contextValue,
|
|
36
|
-
env: process.env,
|
|
37
|
-
result,
|
|
38
|
-
}));
|
|
39
|
-
params.liveQueryStore
|
|
40
|
-
.invalidate(invalidationPaths)
|
|
41
|
-
.catch((e) => params.logger.warn(`Invalidation failed for ${path}: ${e.message}`));
|
|
42
|
-
}
|
|
43
|
-
},
|
|
44
|
-
}));
|
|
45
|
-
});
|
|
46
|
-
},
|
|
47
|
-
};
|
|
48
|
-
},
|
|
49
|
-
};
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
function useMeshLiveQuery(options) {
|
|
53
|
-
var _a;
|
|
54
|
-
options.logger.debug(`Creating Live Query Store`);
|
|
55
|
-
const liveQueryStore = new inMemoryLiveQueryStore.InMemoryLiveQueryStore({
|
|
56
|
-
includeIdentifierExtension: true,
|
|
57
|
-
});
|
|
58
|
-
(_a = options.polling) === null || _a === void 0 ? void 0 : _a.forEach(pollingConfig => {
|
|
59
|
-
const interval = setInterval(() => {
|
|
60
|
-
liveQueryStore
|
|
61
|
-
.invalidate(pollingConfig.invalidate)
|
|
62
|
-
.catch((e) => options.logger.warn(`Invalidation failed for ${pollingConfig.invalidate}: ${e.message}`));
|
|
63
|
-
}, pollingConfig.interval);
|
|
64
|
-
const id = options.pubsub.subscribe('destroy', () => {
|
|
65
|
-
clearInterval(interval);
|
|
66
|
-
options.pubsub.unsubscribe(id);
|
|
67
|
-
});
|
|
68
|
-
});
|
|
69
|
-
return {
|
|
70
|
-
onPluginInit({ addPlugin }) {
|
|
71
|
-
var _a;
|
|
72
|
-
addPlugin(liveQuery.useLiveQuery({ liveQueryStore }));
|
|
73
|
-
if ((_a = options.invalidations) === null || _a === void 0 ? void 0 : _a.length) {
|
|
74
|
-
addPlugin(useInvalidateByResult({ liveQueryStore, invalidations: options.invalidations, logger: options.logger }));
|
|
75
|
-
}
|
|
76
|
-
},
|
|
77
|
-
};
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
module.exports = useMeshLiveQuery;
|
package/index.mjs
DELETED
|
@@ -1,78 +0,0 @@
|
|
|
1
|
-
import { useLiveQuery } from '@envelop/live-query';
|
|
2
|
-
import { InMemoryLiveQueryStore } from '@n1ru4l/in-memory-live-query-store';
|
|
3
|
-
import { getInterpolatedStringFactory } from '@graphql-mesh/string-interpolation';
|
|
4
|
-
import { getOperationAST, TypeInfo, visit, visitWithTypeInfo } from 'graphql';
|
|
5
|
-
|
|
6
|
-
function useInvalidateByResult(params) {
|
|
7
|
-
const liveQueryInvalidationFactoryMap = new Map();
|
|
8
|
-
params.invalidations.forEach(liveQueryInvalidation => {
|
|
9
|
-
const rawInvalidationPaths = liveQueryInvalidation.invalidate;
|
|
10
|
-
const factories = rawInvalidationPaths.map(rawInvalidationPath => getInterpolatedStringFactory(rawInvalidationPath));
|
|
11
|
-
liveQueryInvalidationFactoryMap.set(liveQueryInvalidation.field, factories);
|
|
12
|
-
});
|
|
13
|
-
return {
|
|
14
|
-
onExecute() {
|
|
15
|
-
return {
|
|
16
|
-
onExecuteDone({ args: executionArgs, result }) {
|
|
17
|
-
queueMicrotask(() => {
|
|
18
|
-
const { schema, document, operationName, rootValue, contextValue } = executionArgs;
|
|
19
|
-
const operationAST = getOperationAST(document, operationName);
|
|
20
|
-
if (!operationAST) {
|
|
21
|
-
throw new Error(`Operation couldn't be found`);
|
|
22
|
-
}
|
|
23
|
-
const typeInfo = new TypeInfo(schema);
|
|
24
|
-
visit(operationAST, visitWithTypeInfo(typeInfo, {
|
|
25
|
-
Field: () => {
|
|
26
|
-
const parentType = typeInfo.getParentType();
|
|
27
|
-
const fieldDef = typeInfo.getFieldDef();
|
|
28
|
-
const path = `${parentType.name}.${fieldDef.name}`;
|
|
29
|
-
if (liveQueryInvalidationFactoryMap.has(path)) {
|
|
30
|
-
const invalidationPathFactories = liveQueryInvalidationFactoryMap.get(path);
|
|
31
|
-
const invalidationPaths = invalidationPathFactories.map(invalidationPathFactory => invalidationPathFactory({
|
|
32
|
-
root: rootValue,
|
|
33
|
-
context: contextValue,
|
|
34
|
-
env: process.env,
|
|
35
|
-
result,
|
|
36
|
-
}));
|
|
37
|
-
params.liveQueryStore
|
|
38
|
-
.invalidate(invalidationPaths)
|
|
39
|
-
.catch((e) => params.logger.warn(`Invalidation failed for ${path}: ${e.message}`));
|
|
40
|
-
}
|
|
41
|
-
},
|
|
42
|
-
}));
|
|
43
|
-
});
|
|
44
|
-
},
|
|
45
|
-
};
|
|
46
|
-
},
|
|
47
|
-
};
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
function useMeshLiveQuery(options) {
|
|
51
|
-
var _a;
|
|
52
|
-
options.logger.debug(`Creating Live Query Store`);
|
|
53
|
-
const liveQueryStore = new InMemoryLiveQueryStore({
|
|
54
|
-
includeIdentifierExtension: true,
|
|
55
|
-
});
|
|
56
|
-
(_a = options.polling) === null || _a === void 0 ? void 0 : _a.forEach(pollingConfig => {
|
|
57
|
-
const interval = setInterval(() => {
|
|
58
|
-
liveQueryStore
|
|
59
|
-
.invalidate(pollingConfig.invalidate)
|
|
60
|
-
.catch((e) => options.logger.warn(`Invalidation failed for ${pollingConfig.invalidate}: ${e.message}`));
|
|
61
|
-
}, pollingConfig.interval);
|
|
62
|
-
const id = options.pubsub.subscribe('destroy', () => {
|
|
63
|
-
clearInterval(interval);
|
|
64
|
-
options.pubsub.unsubscribe(id);
|
|
65
|
-
});
|
|
66
|
-
});
|
|
67
|
-
return {
|
|
68
|
-
onPluginInit({ addPlugin }) {
|
|
69
|
-
var _a;
|
|
70
|
-
addPlugin(useLiveQuery({ liveQueryStore }));
|
|
71
|
-
if ((_a = options.invalidations) === null || _a === void 0 ? void 0 : _a.length) {
|
|
72
|
-
addPlugin(useInvalidateByResult({ liveQueryStore, invalidations: options.invalidations, logger: options.logger }));
|
|
73
|
-
}
|
|
74
|
-
},
|
|
75
|
-
};
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
export default useMeshLiveQuery;
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { MeshPluginOptions, YamlConfig } from '@graphql-mesh/types';
|
|
2
1
|
import { Plugin } from '@envelop/core';
|
|
2
|
+
import { MeshPluginOptions, YamlConfig } from '@graphql-mesh/types';
|
|
3
3
|
export default function useMeshLiveQuery(options: MeshPluginOptions<YamlConfig.LiveQueryConfig>): Plugin;
|