Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@graphql-tools/executor-urql-exchange": patch
---
dependencies updates:
- Added dependency [`@whatwg-node/promise-helpers@^1.2.4` ↗︎](https://www.npmjs.com/package/@whatwg-node/promise-helpers/v/1.2.4) (to `dependencies`)
5 changes: 5 additions & 0 deletions .changeset/rotten-turtles-serve.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@graphql-tools/executor-urql-exchange': patch
---

Fix sync execution for urql exchange
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
"clean-dist": "rimraf \"packages/**/dist\" && rimraf \".bob\"",
"lint": "cross-env \"ESLINT_USE_FLAT_CONFIG=false\" eslint --ext .ts .",
"postbuild": "tsx scripts/postbuild.ts",
"postinstall": "patch-package",
"postinstall": "patch-package && husky install",
"prerelease": "yarn build",
"prettier": "prettier --cache --ignore-path .gitignore --ignore-path .prettierignore --write --list-different .",
"prettier:check": "prettier --cache --ignore-path .gitignore --ignore-path .prettierignore --check .",
Expand All @@ -59,7 +59,7 @@
"@typescript-eslint/parser": "8.26.1",
"babel-jest": "29.7.0",
"bob-the-bundler": "7.0.1",
"bun": "^1.1.43",
"bun": "1.2.5",
"chalk": "5.4.1",
"concurrently": "9.1.2",
"cross-env": "7.0.3",
Expand Down
11 changes: 8 additions & 3 deletions packages/executors/apollo-link/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,16 @@ function createApolloRequestHandler(executor: Executor): apolloImport.RequestHan
if (disposed) return;

if (isAsyncIterable(results)) {
const asyncIterator = results[Symbol.asyncIterator]();
dispose = () => {
results[Symbol.asyncIterator]().return?.();
asyncIterator.return?.();
};
for await (const result of results) {
observer.next(result);
try {
for await (const result of { [Symbol.asyncIterator]: () => asyncIterator }) {
observer.next(result);
}
} catch (e) {
observer.error(e);
}
} else {
observer.next(results);
Expand Down
1 change: 1 addition & 0 deletions packages/executors/urql-exchange/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
},
"dependencies": {
"@graphql-tools/utils": "^10.8.4",
"@whatwg-node/promise-helpers": "^1.2.4",
"tslib": "^2.4.0"
},
"devDependencies": {
Expand Down
44 changes: 27 additions & 17 deletions packages/executors/urql-exchange/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { OperationTypeNode } from 'graphql';
import { filter, make, merge, mergeMap, pipe, share, Source, takeUntil } from 'wonka';
import { ExecutionRequest, Executor, fakePromise, isAsyncIterable } from '@graphql-tools/utils';
import { ExecutionRequest, Executor, isAsyncIterable } from '@graphql-tools/utils';
import {
AnyVariables,
Exchange,
Expand All @@ -13,6 +13,7 @@ import {
OperationContext,
OperationResult,
} from '@urql/core';
import { handleMaybePromise } from '@whatwg-node/promise-helpers';

export function executorExchange(executor: Executor): Exchange {
function makeYogaSource<TData extends Record<string, any>>(
Expand All @@ -37,9 +38,10 @@ export function executorExchange(executor: Executor): Exchange {
};
return make<OperationResult<TData>>(observer => {
let ended = false;
fakePromise()
.then(() => executor(executionRequest))
.then(result => {
let iterator: AsyncIterator<ExecutionResult>;
handleMaybePromise(
() => executor(executionRequest),
result => {
if (ended || !result) {
return;
}
Expand All @@ -49,8 +51,15 @@ export function executorExchange(executor: Executor): Exchange {
} else {
let prevResult: OperationResult<TData, AnyVariables> | null = null;

return fakePromise().then(async () => {
for await (const value of result) {
iterator = result[Symbol.asyncIterator]() as AsyncIterator<ExecutionResult>;
function iterate() {
if (ended) {
return;
}
return iterator.next().then(({ value, done }) => {
if (done) {
return;
}
if (value) {
if (prevResult && value.incremental) {
prevResult = mergeResultPatch(prevResult, value as ExecutionResult);
Expand All @@ -59,22 +68,23 @@ export function executorExchange(executor: Executor): Exchange {
}
observer.next(prevResult);
}
if (ended) {
break;
}
}
observer.complete();
});
return iterate();
});
}
return handleMaybePromise(
() => iterate(),
() => observer.complete(),
);
}
})
.catch(error => {
},
error => {
observer.next(makeErrorResult(operation, error));
})
.finally(() => {
ended = true;
observer.complete();
});
},
);
return () => {
iterator?.return?.();
ended = true;
};
});
Expand Down
14 changes: 9 additions & 5 deletions packages/executors/urql-exchange/tests/urql-exchange.spec.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
import { setTimeout } from 'timers/promises';
import { createSchema, createYoga, DisposableSymbols } from 'graphql-yoga';
import { createSchema, createYoga } from 'graphql-yoga';
import { pipe, toObservable } from 'wonka';
import { buildHTTPExecutor } from '@graphql-tools/executor-http';
import { ExecutionResult } from '@graphql-tools/utils';
import { createClient } from '@urql/core';
import { AsyncDisposableStack } from '@whatwg-node/disposablestack';
import { testIf } from '../../../testing/utils.js';
import { executorExchange } from '../src/index.js';

describe('URQL Yoga Exchange', () => {
const asyncDisposableStack = new AsyncDisposableStack();
const yoga = createYoga({
logging: false,
maskedErrors: false,
Expand All @@ -26,10 +28,10 @@ describe('URQL Yoga Exchange', () => {
`,
resolvers: {
Query: {
hello: () => 'Hello Urql Client!',
hello: async () => 'Hello Urql Client!',
},
Mutation: {
readFile: (_, args: { file: File }) => args.file.text(),
readFile: async (_, args: { file: File }) => args.file.text(),
},
Subscription: {
alphabet: {
Expand All @@ -48,19 +50,21 @@ describe('URQL Yoga Exchange', () => {
},
}),
});
asyncDisposableStack.use(yoga);

const executor = buildHTTPExecutor({
endpoint: 'http://localhost:4000/graphql',
fetch: yoga.fetch,
File: yoga.fetchAPI.File,
FormData: yoga.fetchAPI.FormData,
});
asyncDisposableStack.use(executor);
const client = createClient({
url: 'http://localhost:4000/graphql',
exchanges: [executorExchange(executor)],
});

afterAll(() => executor[DisposableSymbols.asyncDispose]());
afterAll(() => asyncDisposableStack.disposeAsync());

it('should handle queries correctly', async () => {
const result = await client
Expand Down Expand Up @@ -117,7 +121,7 @@ describe('URQL Yoga Exchange', () => {
expect(i).toBe(3);
},
);
testIf(!globalThis.Bun)('should handle file uploads correctly', async () => {
test('should handle file uploads correctly', async () => {
const query = /* GraphQL */ `
mutation readFile($file: File!) {
readFile(file: $file)
Expand Down
104 changes: 48 additions & 56 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1267,7 +1267,7 @@
dependencies:
tslib "^2.4.0"

"@envelop/core@5.2.3", "@envelop/core@^5.1.0", "@envelop/core@^5.2.3":
"@envelop/core@5.2.3", "@envelop/core@^5.2.3":
version "5.2.3"
resolved "https://registry.yarnpkg.com/@envelop/core/-/core-5.2.3.tgz#ede1dd20b4397c7465ae2190e718829303bcef00"
integrity sha512-KfoGlYD/XXQSc3BkM1/k15+JQbkQ4ateHazeZoWl9P71FsLTDXSjGy6j7QqfhpIDSbxNISqhPMfZHYSbDFOofQ==
Expand Down Expand Up @@ -1545,87 +1545,90 @@
dependencies:
giscus "^1.6.0"

"@graphql-tools/batch-delegate@^9.0.31":
version "9.0.31"
resolved "https://registry.yarnpkg.com/@graphql-tools/batch-delegate/-/batch-delegate-9.0.31.tgz#18e051d975e04931024e5d0456dfd0e6ff48f9fd"
integrity sha512-/ZPdyBPYvdsZsB9MOuHKysRtsZwwbiPO3XqnmorzJnUmBPMjy7vKpVJ9gq7TzCBToeGYfu4nibbdzZEMT39waw==
"@graphql-tools/batch-delegate@^9.0.32":
version "9.0.32"
resolved "https://registry.yarnpkg.com/@graphql-tools/batch-delegate/-/batch-delegate-9.0.32.tgz#3ceb3c00fca685bf869cde721a1ff0a6dc5811e3"
integrity sha512-Zhgh+OnEx2LEk8XdfWKfwRzlsrjUSyyvOqytAJdcgVTrL9cf0+UqGwuPWNU4r0VyReqstJc7I/UYZE7389psxQ==
dependencies:
"@graphql-tools/delegate" "^10.2.13"
"@graphql-tools/delegate" "^10.2.14"
"@graphql-tools/utils" "^10.8.1"
"@whatwg-node/promise-helpers" "^1.0.0"
dataloader "^2.2.3"
tslib "^2.8.1"

"@graphql-tools/batch-execute@^9.0.12":
version "9.0.12"
resolved "https://registry.yarnpkg.com/@graphql-tools/batch-execute/-/batch-execute-9.0.12.tgz#807e393ec6560247eeefb0338a02779a2e7175ab"
integrity sha512-AUKU/KLez9LvBFh8Uur4h5n2cKrHnBFADKyHWMP7/dAuG6vzFES047bYsKQR2oWhzO26ucQMVBm9GGw1+VCv8A==
"@graphql-tools/batch-execute@^9.0.13":
version "9.0.13"
resolved "https://registry.yarnpkg.com/@graphql-tools/batch-execute/-/batch-execute-9.0.13.tgz#f103c334af6df82efc629f7331e2e97e0822f842"
integrity sha512-CgxmfhMv/QYsZMKhmMOMLM5pt/8VaH/fbgebn/9eHQ5nik3qC5U3GD/mHh6Udxz29Rt0UdmHPH2Wo29+pIgsLg==
dependencies:
"@graphql-tools/utils" "^10.8.1"
"@whatwg-node/promise-helpers" "^1.0.0"
dataloader "^2.2.3"
tslib "^2.8.1"

"@graphql-tools/delegate@^10.1.2", "@graphql-tools/delegate@^10.2.13":
version "10.2.13"
resolved "https://registry.yarnpkg.com/@graphql-tools/delegate/-/delegate-10.2.13.tgz#7017f233c32ae62b9aa3fbd3af4e27c8075b6d27"
integrity sha512-FpxbNZ5OA3LYlU1CFMlHvNLyBgSKlDu/D1kffVbd4PhY82F6YnKKobAwwwA8ar8BhGOIf+XGw3+ybZa0hZs7WA==
"@graphql-tools/delegate@^10.1.2", "@graphql-tools/delegate@^10.2.14":
version "10.2.14"
resolved "https://registry.yarnpkg.com/@graphql-tools/delegate/-/delegate-10.2.14.tgz#cda471a770546203663ff01f52436f83b26b1467"
integrity sha512-s0m5ArQQS66IXnKjegIpNkevt9Md5LhDL55xwFSHttJYgo31PT5N6Z/PWvaOj7OKuGZLzua4rJOAzdfA9YRlhA==
dependencies:
"@graphql-tools/batch-execute" "^9.0.12"
"@graphql-tools/batch-execute" "^9.0.13"
"@graphql-tools/executor" "^1.3.10"
"@graphql-tools/schema" "^10.0.11"
"@graphql-tools/utils" "^10.8.1"
"@repeaterjs/repeater" "^3.0.6"
"@whatwg-node/promise-helpers" "^1.0.0"
dataloader "^2.2.3"
dset "^3.1.2"
tslib "^2.8.1"

"@graphql-tools/executor-common@^0.0.3":
version "0.0.3"
resolved "https://registry.yarnpkg.com/@graphql-tools/executor-common/-/executor-common-0.0.3.tgz#f8a25a7d8f3f9cb21935817bc99f2bf84e6b870b"
integrity sha512-DKp6Ut4WXVB6FJIey2ajacQO1yTv4sbLtvTRxdytCunFFWFSF3NNtfGWoULE6pNBAVYUY4a981u+X0A70mK1ew==
"@graphql-tools/executor-common@^0.0.4":
version "0.0.4"
resolved "https://registry.yarnpkg.com/@graphql-tools/executor-common/-/executor-common-0.0.4.tgz#763603a6d7a22bb09d67ce682e84a0d730ff2bf9"
integrity sha512-SEH/OWR+sHbknqZyROCFHcRrbZeUAyjCsgpVWCRjqjqRbiJiXq6TxNIIOmpXgkrXWW/2Ev4Wms6YSGJXjdCs6Q==
dependencies:
"@envelop/core" "^5.1.0"
"@envelop/core" "^5.2.3"
"@graphql-tools/utils" "^10.8.1"

"@graphql-tools/executor-graphql-ws@^2.0.1":
version "2.0.3"
resolved "https://registry.yarnpkg.com/@graphql-tools/executor-graphql-ws/-/executor-graphql-ws-2.0.3.tgz#894cafea1ad622932d6d27476f59c0a6b6320e5a"
integrity sha512-IIhENlCZ/5MdpoRSOM30z4hlBT4uOT1J2n6VI67/N1PI2zjxu7RWXlG2ZvmHl83XlVHu3yce5vE02RpS7Y+c4g==
version "2.0.4"
resolved "https://registry.yarnpkg.com/@graphql-tools/executor-graphql-ws/-/executor-graphql-ws-2.0.4.tgz#30ab9f318796b5942929809564c2383e92663496"
integrity sha512-FRNAFqHPOaiGqtc4GcXzGTOpJx01BK3CPtblTaUE90aauZIYU/P3/3z8TvakHL6k05dVq78nNxBBhgTA2hnFOA==
dependencies:
"@graphql-tools/executor-common" "^0.0.3"
"@graphql-tools/executor-common" "^0.0.4"
"@graphql-tools/utils" "^10.8.1"
"@whatwg-node/disposablestack" "^0.0.5"
"@whatwg-node/disposablestack" "^0.0.6"
graphql-ws "^6.0.3"
isomorphic-ws "^5.0.0"
tslib "^2.8.1"
ws "^8.17.1"

"@graphql-tools/executor-http@^1.1.9":
version "1.2.8"
resolved "https://registry.yarnpkg.com/@graphql-tools/executor-http/-/executor-http-1.2.8.tgz#e00784960224c7b5262775e5d4fd137a15eb25e7"
integrity sha512-hrlNqBm7M13HEVouNeJ8D9aPNMtoq8YlbiDdkQYq4LbNOTMpuFB13fRR9+6158l3VHKSHm9pRXDWFwfVZ3r1Xg==
version "1.3.0"
resolved "https://registry.yarnpkg.com/@graphql-tools/executor-http/-/executor-http-1.3.0.tgz#9bee620732c83796f10ac23616281cc24a97c10d"
integrity sha512-0NVrpUTvPRuvD5txm494xBJuxIHStYAuL9y6cURrJ0YCX6TpwmVhY8jFFAs67GAEDgVuOTq/BxRDoKMo6j0EAg==
dependencies:
"@graphql-tools/executor-common" "^0.0.3"
"@graphql-tools/executor-common" "^0.0.4"
"@graphql-tools/utils" "^10.8.1"
"@repeaterjs/repeater" "^3.0.4"
"@whatwg-node/disposablestack" "^0.0.5"
"@whatwg-node/disposablestack" "^0.0.6"
"@whatwg-node/fetch" "^0.10.4"
extract-files "^11.0.0"
"@whatwg-node/promise-helpers" "^1.0.0"
meros "^1.2.1"
tslib "^2.8.1"
value-or-promise "^1.0.12"

"@graphql-tools/stitch@^9.3.4":
version "9.4.18"
resolved "https://registry.yarnpkg.com/@graphql-tools/stitch/-/stitch-9.4.18.tgz#2b5f44c57f3e87af341b9e22dc0fc289da5343e5"
integrity sha512-s7SnpPRSpTth6JJ9ygC/gYBqUwuBPniT+5+VvS7S0WTClC5xNL/UwiGjM+b4nhGAtHNWJOM8CbPYLOVBEvusGA==
version "9.4.19"
resolved "https://registry.yarnpkg.com/@graphql-tools/stitch/-/stitch-9.4.19.tgz#609a3d6904e94a1adb17540d367a4cab05308c22"
integrity sha512-xYxTTEEfkyQ651fJACF6SvratbQoYKiysUP8Zhz7u58Cfsvu3MsyzaUqyDap1XTJmmw8Pq9/7JeIBc/tt/4kIw==
dependencies:
"@graphql-tools/batch-delegate" "^9.0.31"
"@graphql-tools/delegate" "^10.2.13"
"@graphql-tools/batch-delegate" "^9.0.32"
"@graphql-tools/delegate" "^10.2.14"
"@graphql-tools/executor" "^1.3.10"
"@graphql-tools/merge" "^9.0.12"
"@graphql-tools/schema" "^10.0.11"
"@graphql-tools/utils" "^10.8.1"
"@graphql-tools/wrap" "^10.0.31"
"@graphql-tools/wrap" "^10.0.32"
"@whatwg-node/promise-helpers" "^1.0.0"
tslib "^2.8.1"

"@graphql-tools/utils@^8.5.2":
Expand All @@ -1635,14 +1638,15 @@
dependencies:
tslib "^2.4.0"

"@graphql-tools/wrap@^10.0.16", "@graphql-tools/wrap@^10.0.31":
version "10.0.31"
resolved "https://registry.yarnpkg.com/@graphql-tools/wrap/-/wrap-10.0.31.tgz#2cc33a0596808228cf681f96aed9fe04a6f58207"
integrity sha512-W4sPLcvc4ZAPLpHifZQJQabL6WoXyzUWMh4n/NwI8mXAJrU4JAKKbJqONS8WC31i0gN+VCkBaSwssgbtbUz1Qw==
"@graphql-tools/wrap@^10.0.16", "@graphql-tools/wrap@^10.0.32":
version "10.0.32"
resolved "https://registry.yarnpkg.com/@graphql-tools/wrap/-/wrap-10.0.32.tgz#7b1e66f409aaa4a8bbe3faf7490ab4bc9142e39f"
integrity sha512-IQRzsmT5Q/NJW9zS+Vz9KClGckbJ7Qz71pDhENuk/pQAY9RLMM58Z+3AtXJFfXg0pCA9m6IZ8nu54UrrbY1jfQ==
dependencies:
"@graphql-tools/delegate" "^10.2.13"
"@graphql-tools/delegate" "^10.2.14"
"@graphql-tools/schema" "^10.0.11"
"@graphql-tools/utils" "^10.8.1"
"@whatwg-node/promise-helpers" "^1.0.0"
tslib "^2.8.1"

"@graphql-typed-document-node/core@^3.1.1", "@graphql-typed-document-node/core@^3.2.0":
Expand Down Expand Up @@ -3767,13 +3771,6 @@
"@webassemblyjs/ast" "1.14.1"
"@xtuc/long" "4.2.2"

"@whatwg-node/disposablestack@^0.0.5":
version "0.0.5"
resolved "https://registry.yarnpkg.com/@whatwg-node/disposablestack/-/disposablestack-0.0.5.tgz#cd646b1ef60a36972e018ab21f412a3539c6deec"
integrity sha512-9lXugdknoIequO4OYvIjhygvfSEgnO8oASLqLelnDhkRjgBZhc39shC3QSlZuyDO9bgYSIVa2cHAiN+St3ty4w==
dependencies:
tslib "^2.6.3"

"@whatwg-node/disposablestack@^0.0.6":
version "0.0.6"
resolved "https://registry.yarnpkg.com/@whatwg-node/disposablestack/-/disposablestack-0.0.6.tgz#2064a1425ea66194def6df0c7a1851b6939c82bb"
Expand Down Expand Up @@ -4423,7 +4420,7 @@ buffer-from@^1.0.0:
resolved "https://registry.yarnpkg.com/buffer-from/-/buffer-from-1.1.2.tgz#2b146a6fd72e80b4f55d255f35ed59a3a9a41bd5"
integrity sha512-E+XQCRwSbaaiChtv6k6Dwgc+bx+Bs6vuKJHHl5kox/BaKbhiXzqQOwK4cO22yElGp2OCmjwVhT3HmxgyPGnJfQ==

bun@^1.1.43:
bun@1.2.5:
version "1.2.5"
resolved "https://registry.yarnpkg.com/bun/-/bun-1.2.5.tgz#1e8e7a12ca98ebeba232590a1a5fbbc4633f3ab4"
integrity sha512-fbQLt+DPiGUrPKdmsHRRT7cQAlfjdxPVFvLZrsUPmKiTdv+pU50ypdx9yRJluknSbyaZchFVV7Lx2KXikXKX2Q==
Expand Down Expand Up @@ -12058,11 +12055,6 @@ v8-to-istanbul@^9.0.1:
"@types/istanbul-lib-coverage" "^2.0.1"
convert-source-map "^2.0.0"

value-or-promise@^1.0.12:
version "1.0.12"
resolved "https://registry.yarnpkg.com/value-or-promise/-/value-or-promise-1.0.12.tgz#0e5abfeec70148c78460a849f6b003ea7986f15c"
integrity sha512-Z6Uz+TYwEqE7ZN50gwn+1LCVo9ZVrpxRPOhOLnncYkY1ZzOYtrX8Fwf/rFktZ8R5mJms6EZf5TqNOMeZmnPq9Q==

vary@~1.1.2:
version "1.1.2"
resolved "https://registry.yarnpkg.com/vary/-/vary-1.1.2.tgz#2299f02c6ded30d4a5961b0b9f74524a18f634fc"
Expand Down
Loading