Skip to content

Commit

Permalink
Revert "Bump whatwg node" (#3478)
Browse files Browse the repository at this point in the history
  • Loading branch information
ardatan authored Nov 11, 2024
1 parent b733a89 commit 7b330ec
Show file tree
Hide file tree
Showing 30 changed files with 297 additions and 305 deletions.

This file was deleted.

This file was deleted.

10 changes: 0 additions & 10 deletions .changeset/graphql-yoga-3474-dependencies.md

This file was deleted.

2 changes: 1 addition & 1 deletion examples/apollo-federation/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,6 @@
},
"devDependencies": {
"@apollo/gateway": "2.4.7",
"@whatwg-node/fetch": "^0.10.1"
"@whatwg-node/fetch": "^0.9.22"
}
}
2 changes: 1 addition & 1 deletion examples/bun-yoga-ws/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"graphql-yoga": "^5.3.1"
},
"devDependencies": {
"@whatwg-node/fetch": "^0.10.1",
"@whatwg-node/fetch": "^0.9.22",
"typescript": "^5.4.5"
}
}
2 changes: 1 addition & 1 deletion examples/bun/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"graphql-yoga": "5.3.1"
},
"devDependencies": {
"@whatwg-node/fetch": "^0.10.1",
"@whatwg-node/fetch": "^0.9.22",
"typescript": "^5.4.5"
}
}
2 changes: 1 addition & 1 deletion examples/cloudflare-modules/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
},
"devDependencies": {
"@cloudflare/workers-types": "4.20230518.0",
"@whatwg-node/fetch": "^0.10.1",
"@whatwg-node/fetch": "^0.9.22",
"typescript": "5.5.4",
"wrangler": "3.57.1"
}
Expand Down
2 changes: 1 addition & 1 deletion examples/error-handling/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"start": "ts-node src/index.ts"
},
"dependencies": {
"@whatwg-node/fetch": "^0.10.1",
"@whatwg-node/fetch": "^0.9.22",
"graphql": "^16.1.0",
"graphql-yoga": "workspace:*"
},
Expand Down
2 changes: 1 addition & 1 deletion examples/fastify/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"start": "ts-node src/index.ts"
},
"dependencies": {
"@whatwg-node/fetch": "^0.10.1",
"@whatwg-node/fetch": "^0.9.22",
"fastify": "4.17.0",
"graphql-yoga": "workspace:*",
"pino-pretty": "11.2.1"
Expand Down
2 changes: 1 addition & 1 deletion examples/file-upload-nextjs-pothos/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
},
"devDependencies": {
"@types/react": "^18.0.17",
"@whatwg-node/fetch": "^0.10.1",
"@whatwg-node/fetch": "^0.9.22",
"eslint": "8.42.0",
"eslint-config-next": "13.4.12",
"typescript": "5.5.4"
Expand Down
2 changes: 1 addition & 1 deletion examples/file-upload-nexus/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"nexus": "^1.3.0"
},
"devDependencies": {
"@whatwg-node/fetch": "^0.10.1",
"@whatwg-node/fetch": "^0.9.22",
"ts-node": "10.9.1",
"typescript": "5.5.4"
}
Expand Down
2 changes: 1 addition & 1 deletion examples/file-upload/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@
"ts-node": "10.9.1"
},
"devDependencies": {
"@whatwg-node/fetch": "^0.10.1"
"@whatwg-node/fetch": "^0.9.22"
}
}
2 changes: 1 addition & 1 deletion examples/generic-auth/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
},
"devDependencies": {
"@types/node": "20.14.12",
"@whatwg-node/fetch": "^0.10.1",
"@whatwg-node/fetch": "^0.9.22",
"cross-env": "7.0.3",
"ts-node": "10.9.1",
"ts-node-dev": "2.0.0",
Expand Down
2 changes: 1 addition & 1 deletion examples/hapi/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"graphql-yoga": "workspace:*"
},
"devDependencies": {
"@whatwg-node/fetch": "^0.10.1",
"@whatwg-node/fetch": "^0.9.22",
"ts-node": "10.9.1",
"typescript": "5.5.4"
}
Expand Down
2 changes: 1 addition & 1 deletion examples/nextjs-app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,6 @@
"typescript": "5.5.4"
},
"devDependencies": {
"@whatwg-node/fetch": "^0.10.1"
"@whatwg-node/fetch": "^0.9.22"
}
}
2 changes: 1 addition & 1 deletion examples/request-cancelation/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
},
"devDependencies": {
"@types/node": "20.14.12",
"@whatwg-node/fetch": "^0.10.1",
"@whatwg-node/fetch": "^0.9.22",
"cross-env": "7.0.3",
"ts-node": "10.9.1",
"ts-node-dev": "2.0.0",
Expand Down
2 changes: 1 addition & 1 deletion examples/response-cache/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
},
"devDependencies": {
"@types/node": "20.14.12",
"@whatwg-node/fetch": "^0.10.1",
"@whatwg-node/fetch": "^0.9.22",
"cross-env": "7.0.3",
"ts-node": "10.9.1",
"ts-node-dev": "2.0.0",
Expand Down
2 changes: 1 addition & 1 deletion examples/service-worker/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"graphql-yoga": "workspace:*"
},
"devDependencies": {
"@whatwg-node/fetch": "^0.10.1",
"@whatwg-node/fetch": "^0.9.22",
"typescript": "5.5.4",
"wrangler": "3.57.1"
}
Expand Down
2 changes: 1 addition & 1 deletion examples/uwebsockets/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
},
"devDependencies": {
"@types/ws": "8.5.4",
"@whatwg-node/fetch": "^0.10.1",
"@whatwg-node/fetch": "^0.9.22",
"ws": "8.13.0"
}
}
4 changes: 2 additions & 2 deletions packages/graphql-yoga/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@
"@graphql-tools/utils": "^10.3.2",
"@graphql-yoga/logger": "workspace:^",
"@graphql-yoga/subscription": "workspace:^",
"@whatwg-node/fetch": "^0.10.1",
"@whatwg-node/server": "^0.9.54",
"@whatwg-node/fetch": "^0.9.22",
"@whatwg-node/server": "^0.9.50",
"dset": "^3.1.1",
"lru-cache": "^10.0.0",
"tslib": "^2.5.2"
Expand Down
71 changes: 28 additions & 43 deletions packages/graphql-yoga/src/plugins/result-processor/multipart.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { ExecutionResult } from 'graphql';
import { isAsyncIterable } from '@envelop/core';
import { fakePromise } from '@whatwg-node/server';
import { getResponseInitByRespectingErrors } from '../../error.js';
import { FetchAPI, MaybeArray } from '../../types.js';
import { ResultProcessorInput } from '../types.js';
Expand All @@ -16,7 +15,8 @@ export function processMultipartResult(result: ResultProcessorInput, fetchAPI: F
const responseInit = getResponseInitByRespectingErrors(result, headersInit);

let iterator: AsyncIterator<MaybeArray<ExecutionResult>>;
const textEncoderStream = new fetchAPI.TextEncoderStream();

const textEncoder = new fetchAPI.TextEncoder();

const readableStream = new fetchAPI.ReadableStream({
start(controller) {
Expand All @@ -27,65 +27,50 @@ export function processMultipartResult(result: ResultProcessorInput, fetchAPI: F
iterator = {
next: () => {
if (finished) {
return fakePromise({ done: true, value: null });
return Promise.resolve({ done: true, value: null });
}
finished = true;
return fakePromise({ done: false, value: result });
return Promise.resolve({ done: false, value: result });
},
};
}
controller.enqueue('\r\n');
controller.enqueue(`---`);
controller.enqueue(textEncoder.encode('\r\n'));
controller.enqueue(textEncoder.encode(`---`));
},
pull(controller): void | Promise<void> {
async pull(controller) {
try {
return iterator.next().then(
({ value, done }) => {
if (value != null) {
controller.enqueue('\r\n');
const { done, value } = await iterator.next();
if (value != null) {
controller.enqueue(textEncoder.encode('\r\n'));

controller.enqueue('Content-Type: application/json; charset=utf-8');
controller.enqueue('\r\n');
controller.enqueue(textEncoder.encode('Content-Type: application/json; charset=utf-8'));
controller.enqueue(textEncoder.encode('\r\n'));

const chunk = jsonStringifyResultWithoutInternals(value);
const chunk = jsonStringifyResultWithoutInternals(value);
const encodedChunk = textEncoder.encode(chunk);

controller.enqueue('Content-Length: ' + chunk.length);
controller.enqueue('\r\n');
controller.enqueue(textEncoder.encode('Content-Length: ' + encodedChunk.byteLength));
controller.enqueue(textEncoder.encode('\r\n'));

controller.enqueue('\r\n');
controller.enqueue(chunk);
controller.enqueue('\r\n');
controller.enqueue(textEncoder.encode('\r\n'));
controller.enqueue(encodedChunk);
controller.enqueue(textEncoder.encode('\r\n'));

controller.enqueue('---');
}
controller.enqueue(textEncoder.encode('---'));
}

if (done) {
controller.enqueue('--\r\n');
controller.close();
}
},
err => controller.error(err),
);
if (done) {
controller.enqueue(textEncoder.encode('--\r\n'));
controller.close();
}
} catch (err) {
controller.error(err);
}
},
cancel(e) {
return iterator
?.return?.(e)
?.finally?.(() =>
Promise.all([textEncoderStream.writable.abort(e), textEncoderStream.readable.cancel(e)]),
)
?.then?.(
() => {
// ignore
},
() => {
// ignore
},
);
async cancel(e) {
await iterator.return?.(e);
},
});

return new fetchAPI.Response(readableStream.pipeThrough(textEncoderStream), responseInit);
return new fetchAPI.Response(readableStream, responseInit);
}
19 changes: 3 additions & 16 deletions packages/graphql-yoga/src/plugins/result-processor/regular.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
} from '../../error.js';
import { FetchAPI } from '../../types.js';
import { ResultProcessorInput } from '../types.js';
import { jsonStringifyResultWithoutInternals, omitInternalsFromResultErrors } from './stringify.js';
import { jsonStringifyResultWithoutInternals } from './stringify.js';

export function processRegularResult(
executionResult: ResultProcessorInput,
Expand Down Expand Up @@ -39,20 +39,7 @@ export function processRegularResult(
),
);

const isArrayResult = Array.isArray(executionResult);
const hasCustomSerializer = isArrayResult
? executionResult.some(r => r.stringify)
: executionResult.stringify;
const responseBody = jsonStringifyResultWithoutInternals(executionResult);

if (hasCustomSerializer) {
const responseBody = jsonStringifyResultWithoutInternals(executionResult);
return new fetchAPI.Response(responseBody, responseInit);
}

return fetchAPI.Response.json(
isArrayResult
? executionResult.map(omitInternalsFromResultErrors)
: omitInternalsFromResultErrors(executionResult),
responseInit,
);
return new fetchAPI.Response(responseBody, responseInit);
}
Loading

0 comments on commit 7b330ec

Please sign in to comment.