Skip to content

Commit

Permalink
Fix issue where a bare install had some issues with a @types/node i…
Browse files Browse the repository at this point in the history
…mport in some cases (#11141)

Moves the response iterator helpers over to the http link where they are used and removes them from `@apollo/client/utilities`. These helpers were added in an [alpha of 3.8](4207078#diff-4f4a4192cd629d907783a6baf48c530f39d6a43181dd3515cc46231868e0ed08R99) and thus were not exported in versions <= 3.7.x.
  • Loading branch information
jerelmiller authored Aug 10, 2023
1 parent 4b501e1 commit c469b16
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 50 deletions.
16 changes: 16 additions & 0 deletions .changeset/pretty-terms-fix.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
---
"@apollo/client": patch
---

Remove newly exported response iterator helpers that caused problems on some installs where `@types/node` was not available.

**IMPORTANT**

The following exports were added in version 3.8.0 that are removed with this patch.

- `isAsyncIterableIterator`
- `isBlob`
- `isNodeReadableStream`
- `isNodeResponse`
- `isReadableStream`
- `isStreamableBlob`
6 changes: 0 additions & 6 deletions src/__tests__/__snapshots__/exports.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -427,25 +427,19 @@ Array [
"hasDirectives",
"isApolloPayloadResult",
"isArray",
"isAsyncIterableIterator",
"isBlob",
"isDocumentNode",
"isExecutionPatchIncrementalResult",
"isExecutionPatchInitialResult",
"isExecutionPatchResult",
"isField",
"isInlineFragment",
"isMutationOperation",
"isNodeReadableStream",
"isNodeResponse",
"isNonEmptyArray",
"isNonNullObject",
"isPlainObject",
"isQueryOperation",
"isReadableStream",
"isReference",
"isStatefulPromise",
"isStreamableBlob",
"isSubscriptionOperation",
"iterateObserversSafely",
"makeReference",
Expand Down
6 changes: 3 additions & 3 deletions src/link/http/__tests__/responseIteratorNoAsyncIterator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ import { Readable } from "stream";
// which do not execute when isAsyncIterableIterator is true
// See: https://github.com/facebook/jest/issues/2582#issuecomment-655110424

jest.mock("../../../utilities/common/responseIterator", () => ({
jest.mock("../../../utilities/index.js", () => ({
__esModule: true,
...jest.requireActual("../../../utilities/common/responseIterator"),
isAsyncIterableIterator: jest.fn(() => false),
...jest.requireActual("../../../utilities/index.js"),
canUseAsyncIteratorSymbol: false,
}));

const sampleDeferredQuery = gql`
Expand Down
39 changes: 31 additions & 8 deletions src/link/http/responseIterator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,43 @@
*/

import type { Response as NodeResponse } from "node-fetch";
import {
isAsyncIterableIterator,
isBlob,
isNodeResponse,
isNodeReadableStream,
isReadableStream,
isStreamableBlob,
} from "../../utilities/index.js";
import type { Readable as NodeReadableStream } from "stream";
import { canUseAsyncIteratorSymbol } from "../../utilities/index.js";

import asyncIterator from "./iterators/async.js";
import nodeStreamIterator from "./iterators/nodeStream.js";
import promiseIterator from "./iterators/promise.js";
import readerIterator from "./iterators/reader.js";

function isNodeResponse(value: any): value is NodeResponse {
return !!(value as NodeResponse).body;
}

function isReadableStream(value: any): value is ReadableStream<any> {
return !!(value as ReadableStream<any>).getReader;
}

function isAsyncIterableIterator(
value: any
): value is AsyncIterableIterator<any> {
return !!(
canUseAsyncIteratorSymbol &&
(value as AsyncIterableIterator<any>)[Symbol.asyncIterator]
);
}

function isStreamableBlob(value: any): value is Blob {
return !!(value as Blob).stream;
}

function isBlob(value: any): value is Blob {
return !!(value as Blob).arrayBuffer;
}

function isNodeReadableStream(value: any): value is NodeReadableStream {
return !!(value as NodeReadableStream).pipe;
}

export function responseIterator<T>(
response: Response | NodeResponse
): AsyncIterableIterator<T> {
Expand Down
32 changes: 0 additions & 32 deletions src/utilities/common/responseIterator.ts

This file was deleted.

1 change: 0 additions & 1 deletion src/utilities/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,6 @@ export * from "./common/compact.js";
export * from "./common/makeUniqueId.js";
export * from "./common/stringifyForDisplay.js";
export * from "./common/mergeOptions.js";
export * from "./common/responseIterator.js";
export * from "./common/incrementalResult.js";

export { omitDeep } from "./common/omitDeep.js";
Expand Down

0 comments on commit c469b16

Please sign in to comment.