@graphql-mesh/urql-exchange 3.1.0 → 3.1.1-alpha-2313f35ea.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.
Files changed (3) hide show
  1. package/index.js +11 -16
  2. package/index.mjs +12 -17
  3. package/package.json +3 -2
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 asyncIterator = typeof Symbol !== 'undefined' ? Symbol.asyncIterator : null;
9
- const makeExecuteSource = (operation, options, document, variables, context, operationName, rootValue) => {
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
- Promise.resolve()
13
- .then(() => {
14
- if (ended)
15
- return;
16
- if (operation.kind === 'subscription') {
17
- return options.subscribe(document, variables, context, rootValue, operationName);
18
- }
19
- return options.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 (!asyncIterator || !result[asyncIterator]) {
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, options, document, variables, context, ope
35
30
  if (!done && !ended) {
36
31
  return iterator.next().then(next);
37
32
  }
38
- if (ended) {
39
- iterator.return && iterator.return();
33
+ if (ended && iterator.return != null) {
34
+ return iterator.return();
40
35
  }
41
36
  }
42
37
  return iterator.next().then(next);
@@ -62,7 +57,7 @@ const meshExchange = (options) => ({ forward }) => {
62
57
  }), wonka.mergeMap((operation) => {
63
58
  const { key } = operation;
64
59
  const teardown$ = wonka.pipe(sharedOps$, wonka.filter(op => op.kind === 'teardown' && op.key === key));
65
- return wonka.pipe(makeExecuteSource(operation, options, operation.query, operation.variables, {}, core.getOperationName(operation.query), {}), wonka.takeUntil(teardown$));
60
+ return wonka.pipe(makeExecuteSource(operation, options), wonka.takeUntil(teardown$));
66
61
  }));
67
62
  const forwardedOps$ = wonka.pipe(sharedOps$, wonka.filter(operation => operation.kind === 'teardown'), forward);
68
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 { getOperationName, makeResult, makeErrorResult, mergeResultPatch } from '@urql/core';
2
+ import { makeResult, makeErrorResult, getOperationName, mergeResultPatch } from '@urql/core';
3
+ import { isAsyncIterable } from '@graphql-tools/utils';
3
4
 
4
- const asyncIterator = typeof Symbol !== 'undefined' ? Symbol.asyncIterator : null;
5
- const makeExecuteSource = (operation, options, document, variables, context, operationName, rootValue) => {
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
- Promise.resolve()
9
- .then(() => {
10
- if (ended)
11
- return;
12
- if (operation.kind === 'subscription') {
13
- return options.subscribe(document, variables, context, rootValue, operationName);
14
- }
15
- return options.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 (!asyncIterator || !result[asyncIterator]) {
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, options, document, variables, context, ope
31
26
  if (!done && !ended) {
32
27
  return iterator.next().then(next);
33
28
  }
34
- if (ended) {
35
- iterator.return && iterator.return();
29
+ if (ended && iterator.return != null) {
30
+ return iterator.return();
36
31
  }
37
32
  }
38
33
  return iterator.next().then(next);
@@ -58,7 +53,7 @@ const meshExchange = (options) => ({ forward }) => {
58
53
  }), mergeMap((operation) => {
59
54
  const { key } = operation;
60
55
  const teardown$ = pipe(sharedOps$, filter(op => op.kind === 'teardown' && op.key === key));
61
- return pipe(makeExecuteSource(operation, options, operation.query, operation.variables, {}, getOperationName(operation.query), {}), takeUntil(teardown$));
56
+ return pipe(makeExecuteSource(operation, options), takeUntil(teardown$));
62
57
  }));
63
58
  const forwardedOps$ = pipe(sharedOps$, filter(operation => operation.kind === 'teardown'), forward);
64
59
  return merge([executedOps$, forwardedOps$]);
package/package.json CHANGED
@@ -1,14 +1,15 @@
1
1
  {
2
2
  "name": "@graphql-mesh/urql-exchange",
3
- "version": "3.1.0",
3
+ "version": "3.1.1-alpha-2313f35ea.0",
4
4
  "sideEffects": false,
5
5
  "peerDependencies": {
6
- "@graphql-mesh/runtime": "^0.34.4",
6
+ "@graphql-mesh/runtime": "0.34.5-alpha-2313f35ea.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
+ "@graphql-tools/utils": "8.6.9",
12
13
  "tslib": "2.4.0"
13
14
  },
14
15
  "repository": {