@graphql-mesh/urql-exchange 8.0.6-alpha-20221115171553-53ea709bb → 8.0.6-alpha-20221115232443-00e600ae9
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/{typings/index.d.ts → index.d.ts} +0 -0
- package/{cjs/index.js → index.js} +22 -19
- package/{esm/index.js → index.mjs} +6 -3
- package/package.json +14 -21
- package/cjs/package.json +0 -1
- package/typings/index.d.cts +0 -8
|
File without changes
|
|
@@ -1,29 +1,31 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
exports
|
|
4
|
-
|
|
5
|
-
const
|
|
6
|
-
const
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
const wonka = require('wonka');
|
|
6
|
+
const core = require('@urql/core');
|
|
7
|
+
const utils = require('@graphql-tools/utils');
|
|
8
|
+
|
|
7
9
|
const ROOT_VALUE = {};
|
|
8
10
|
const makeExecuteSource = (operation, options) => {
|
|
9
11
|
const operationFn = operation.kind === 'subscription' ? options.subscribe : options.execute;
|
|
10
|
-
const operationName =
|
|
11
|
-
return
|
|
12
|
+
const operationName = core.getOperationName(operation.query);
|
|
13
|
+
return wonka.make(observer => {
|
|
12
14
|
let ended = false;
|
|
13
15
|
operationFn(operation.query, operation.variables, operation.context, ROOT_VALUE, operationName)
|
|
14
16
|
.then((result) => {
|
|
15
17
|
if (ended || !result) {
|
|
16
18
|
return;
|
|
17
19
|
}
|
|
18
|
-
else if (!
|
|
19
|
-
observer.next(
|
|
20
|
+
else if (!utils.isAsyncIterable(result)) {
|
|
21
|
+
observer.next(core.makeResult(operation, result));
|
|
20
22
|
return;
|
|
21
23
|
}
|
|
22
24
|
const iterator = result[Symbol.asyncIterator]();
|
|
23
25
|
let prevResult = null;
|
|
24
26
|
function next({ done, value }) {
|
|
25
27
|
if (value) {
|
|
26
|
-
observer.next((prevResult = prevResult ?
|
|
28
|
+
observer.next((prevResult = prevResult ? core.mergeResultPatch(prevResult, value) : core.makeResult(operation, value)));
|
|
27
29
|
}
|
|
28
30
|
if (!done && !ended) {
|
|
29
31
|
return iterator.next().then(next);
|
|
@@ -38,7 +40,7 @@ const makeExecuteSource = (operation, options) => {
|
|
|
38
40
|
observer.complete();
|
|
39
41
|
})
|
|
40
42
|
.catch(error => {
|
|
41
|
-
observer.next(
|
|
43
|
+
observer.next(core.makeErrorResult(operation, error));
|
|
42
44
|
observer.complete();
|
|
43
45
|
});
|
|
44
46
|
return () => {
|
|
@@ -49,16 +51,17 @@ const makeExecuteSource = (operation, options) => {
|
|
|
49
51
|
/** Exchange for executing queries locally on a schema using graphql-js. */
|
|
50
52
|
const meshExchange = (options) => ({ forward }) => {
|
|
51
53
|
return ops$ => {
|
|
52
|
-
const sharedOps$ =
|
|
53
|
-
const executedOps$ =
|
|
54
|
+
const sharedOps$ = wonka.share(ops$);
|
|
55
|
+
const executedOps$ = wonka.pipe(sharedOps$, wonka.filter((operation) => {
|
|
54
56
|
return operation.kind === 'query' || operation.kind === 'mutation' || operation.kind === 'subscription';
|
|
55
|
-
}),
|
|
57
|
+
}), wonka.mergeMap((operation) => {
|
|
56
58
|
const { key } = operation;
|
|
57
|
-
const teardown$ =
|
|
58
|
-
return
|
|
59
|
+
const teardown$ = wonka.pipe(sharedOps$, wonka.filter(op => op.kind === 'teardown' && op.key === key));
|
|
60
|
+
return wonka.pipe(makeExecuteSource(operation, options), wonka.takeUntil(teardown$));
|
|
59
61
|
}));
|
|
60
|
-
const forwardedOps$ =
|
|
61
|
-
return
|
|
62
|
+
const forwardedOps$ = wonka.pipe(sharedOps$, wonka.filter(operation => operation.kind === 'teardown'), forward);
|
|
63
|
+
return wonka.merge([executedOps$, forwardedOps$]);
|
|
62
64
|
};
|
|
63
65
|
};
|
|
66
|
+
|
|
64
67
|
exports.meshExchange = meshExchange;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { makeResult, makeErrorResult,
|
|
1
|
+
import { share, pipe, filter, mergeMap, make, takeUntil, merge } from 'wonka';
|
|
2
|
+
import { makeResult, makeErrorResult, getOperationName, mergeResultPatch } from '@urql/core';
|
|
3
3
|
import { isAsyncIterable } from '@graphql-tools/utils';
|
|
4
|
+
|
|
4
5
|
const ROOT_VALUE = {};
|
|
5
6
|
const makeExecuteSource = (operation, options) => {
|
|
6
7
|
const operationFn = operation.kind === 'subscription' ? options.subscribe : options.execute;
|
|
@@ -44,7 +45,7 @@ const makeExecuteSource = (operation, options) => {
|
|
|
44
45
|
});
|
|
45
46
|
};
|
|
46
47
|
/** Exchange for executing queries locally on a schema using graphql-js. */
|
|
47
|
-
|
|
48
|
+
const meshExchange = (options) => ({ forward }) => {
|
|
48
49
|
return ops$ => {
|
|
49
50
|
const sharedOps$ = share(ops$);
|
|
50
51
|
const executedOps$ = pipe(sharedOps$, filter((operation) => {
|
|
@@ -58,3 +59,5 @@ export const meshExchange = (options) => ({ forward }) => {
|
|
|
58
59
|
return merge([executedOps$, forwardedOps$]);
|
|
59
60
|
};
|
|
60
61
|
};
|
|
62
|
+
|
|
63
|
+
export { meshExchange };
|
package/package.json
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@graphql-mesh/urql-exchange",
|
|
3
|
-
"version": "8.0.6-alpha-
|
|
3
|
+
"version": "8.0.6-alpha-20221115232443-00e600ae9",
|
|
4
4
|
"sideEffects": false,
|
|
5
5
|
"peerDependencies": {
|
|
6
|
-
"@graphql-mesh/runtime": "0.44.32-alpha-
|
|
7
|
-
"graphql": "^15.2.0 || ^16.0.0",
|
|
6
|
+
"@graphql-mesh/runtime": "0.44.32-alpha-20221115232443-00e600ae9",
|
|
8
7
|
"@urql/core": "^2.4.3",
|
|
8
|
+
"graphql": "^15.2.0 || ^16.0.0",
|
|
9
9
|
"wonka": "^4.0.15"
|
|
10
10
|
},
|
|
11
11
|
"dependencies": {
|
|
@@ -18,28 +18,21 @@
|
|
|
18
18
|
"directory": "packages/urql"
|
|
19
19
|
},
|
|
20
20
|
"license": "MIT",
|
|
21
|
-
"main": "
|
|
22
|
-
"module": "
|
|
23
|
-
"typings": "
|
|
21
|
+
"main": "index.js",
|
|
22
|
+
"module": "index.mjs",
|
|
23
|
+
"typings": "index.d.ts",
|
|
24
24
|
"typescript": {
|
|
25
|
-
"definition": "
|
|
25
|
+
"definition": "index.d.ts"
|
|
26
26
|
},
|
|
27
|
-
"type": "module",
|
|
28
27
|
"exports": {
|
|
29
28
|
".": {
|
|
30
|
-
"require":
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
"
|
|
35
|
-
|
|
36
|
-
"default": "./esm/index.js"
|
|
37
|
-
},
|
|
38
|
-
"default": {
|
|
39
|
-
"types": "./typings/index.d.ts",
|
|
40
|
-
"default": "./esm/index.js"
|
|
41
|
-
}
|
|
29
|
+
"require": "./index.js",
|
|
30
|
+
"import": "./index.mjs"
|
|
31
|
+
},
|
|
32
|
+
"./*": {
|
|
33
|
+
"require": "./*.js",
|
|
34
|
+
"import": "./*.mjs"
|
|
42
35
|
},
|
|
43
36
|
"./package.json": "./package.json"
|
|
44
37
|
}
|
|
45
|
-
}
|
|
38
|
+
}
|
package/cjs/package.json
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"type":"commonjs"}
|
package/typings/index.d.cts
DELETED
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import { Exchange } from '@urql/core';
|
|
2
|
-
import { ExecuteMeshFn, SubscribeMeshFn } from '@graphql-mesh/runtime';
|
|
3
|
-
export interface MeshExchangeOptions {
|
|
4
|
-
execute: ExecuteMeshFn;
|
|
5
|
-
subscribe?: SubscribeMeshFn;
|
|
6
|
-
}
|
|
7
|
-
/** Exchange for executing queries locally on a schema using graphql-js. */
|
|
8
|
-
export declare const meshExchange: (options: MeshExchangeOptions) => Exchange;
|