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