Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
97 commits
Select commit Hold shift + click to select a range
87d155a
Add stream tests
jerelmiller Sep 9, 2025
8a80979
First implementation of stream
jerelmiller Sep 9, 2025
3f4230e
Enable all tests
jerelmiller Sep 9, 2025
8e85873
Fix some incorrect assertions on hasIncrementalChunks
jerelmiller Sep 9, 2025
4afb1bc
Remove locations from errors in assertions
jerelmiller Sep 9, 2025
372da81
Formatting
jerelmiller Sep 9, 2025
934aa14
Merge errors for streamed results
jerelmiller Sep 9, 2025
64fa609
Fix incorrect assertions
jerelmiller Sep 9, 2025
9d2388e
Remove assertions on hasIncrementalChunks
jerelmiller Sep 9, 2025
2bb685b
Add necessary changes to writeToStore to handle stream
jerelmiller Sep 9, 2025
9431b44
Add tests for stream with the full client
jerelmiller Sep 9, 2025
e7bf671
Move most stream tests to client.watchQuery folder
jerelmiller Sep 9, 2025
2c11f85
Fix issue with frozen arrays
jerelmiller Sep 9, 2025
54f96f5
Simplify
jerelmiller Sep 9, 2025
bec7bf0
Revert "Add necessary changes to writeToStore to handle stream"
jerelmiller Sep 9, 2025
8f4ccdd
Don't add stream directive to field name
jerelmiller Sep 9, 2025
15ad9f6
Add test for writing stream field to cache
jerelmiller Sep 9, 2025
8e524ea
Add stream to known directives
jerelmiller Sep 9, 2025
5e7e910
Remove check in storeKeyNameFromField
jerelmiller Sep 9, 2025
686bc87
Remove unused imports
jerelmiller Sep 9, 2025
a4acc16
Add more tests for different scenarios
jerelmiller Sep 9, 2025
a1982d1
Rerun api report
jerelmiller Sep 9, 2025
165cac1
Formatting
jerelmiller Sep 9, 2025
58d34e1
More stream tests
jerelmiller Sep 9, 2025
f1925c8
Use toEmitSimilarValue
jerelmiller Sep 9, 2025
dec50ad
Add test for nested stream with defer
jerelmiller Sep 9, 2025
ddf07ed
Add test for defer inside stream
jerelmiller Sep 9, 2025
0d1f981
Add promiseWithResolvers to testing utils
jerelmiller Sep 9, 2025
5436a01
Use shared promiseWithResolvers helper
jerelmiller Sep 9, 2025
f041e0c
Temp rename
jerelmiller Sep 9, 2025
7cdbce6
Fix rename
jerelmiller Sep 9, 2025
01ee8f3
Add tests for stream with defer20220824
jerelmiller Sep 10, 2025
655f48a
Move defer20220824 defer tests to subfolder
jerelmiller Sep 10, 2025
c227576
Update types for defer20220824 handler
jerelmiller Sep 10, 2025
40a5740
Fix assertion on test
jerelmiller Sep 10, 2025
eb0e66e
First pass at implementing stream for old format
jerelmiller Sep 10, 2025
dc6fc72
Fix more incorrect assertions
jerelmiller Sep 10, 2025
d5a4ffb
Remove locations from errors in assertions
jerelmiller Sep 10, 2025
47f6d93
Handle merging null from stream
jerelmiller Sep 10, 2025
76b36d7
Fix more incorrect assertions
jerelmiller Sep 10, 2025
beb904a
Initialize merger on class initialization. Rename to merge
jerelmiller Sep 10, 2025
f1a19b0
Add test file for client.watchQuery with stream on old format
jerelmiller Sep 10, 2025
a071232
Set test to failing to determine what we should do later
jerelmiller Sep 10, 2025
d955184
Update assertions based on behavior of old implementation
jerelmiller Sep 10, 2025
6d2a2e5
Rerun api report
jerelmiller Sep 10, 2025
abaac2f
Add changeset
jerelmiller Sep 10, 2025
77033b7
Update size limits
jerelmiller Sep 10, 2025
89f1cd8
Ensure multipart/mixed header is set when using stream
jerelmiller Sep 10, 2025
956011a
Add tests for alpha.9 in HttpLink
jerelmiller Sep 10, 2025
cc3f04d
Update exports snapshot
jerelmiller Sep 10, 2025
8136cb4
Always create a new DeepMerger
jerelmiller Sep 10, 2025
36948e8
Add test helpers to execute schema incrementally
jerelmiller Sep 10, 2025
b05754d
Add enableEarlyExecution option
jerelmiller Sep 10, 2025
4efb676
Update existing tests to use new execute helpers
jerelmiller Sep 10, 2025
4db41ca
Simplify link in tests
jerelmiller Sep 10, 2025
f516574
Add schemas for the friend list
jerelmiller Sep 10, 2025
6f69581
Add helper to emit values in async iterable
jerelmiller Sep 10, 2025
169cd56
Add offset arg to friendList
jerelmiller Sep 10, 2025
a34af58
Add dom.asyncIterable to tests
jerelmiller Sep 11, 2025
05ca900
Add tests for useSuspenseQuery with @stream
jerelmiller Sep 11, 2025
0b3878a
Fix eslint issue
jerelmiller Sep 11, 2025
ed39d65
WIP cache stream update
jerelmiller Sep 11, 2025
435faa3
Don't set this.data to cacheData and instead merge at the end
jerelmiller Sep 11, 2025
01ac7c5
Extract helper to deep merge
jerelmiller Sep 11, 2025
1a6da06
Add additional test cases
jerelmiller Sep 11, 2025
087757c
Re-enable most tests
jerelmiller Sep 11, 2025
5ee3758
Maintain a queue of the last delivery in case there are no listeners
jerelmiller Sep 11, 2025
e3096ab
Enable some failing tests
jerelmiller Sep 11, 2025
32c0a0e
Use subject to control last test
jerelmiller Sep 11, 2025
84678f5
Use test helpers
jerelmiller Sep 11, 2025
5610434
Fix comment
jerelmiller Sep 11, 2025
28d8247
Remove unused import
jerelmiller Sep 11, 2025
c1d6505
Change expect to assert to fix ts error
jerelmiller Sep 11, 2025
9d08de1
Update exports snapshot
jerelmiller Sep 11, 2025
3807f96
Copy useSuspenseQuery stream tests for older spec
jerelmiller Sep 11, 2025
94c5740
Update details for older spec
jerelmiller Sep 11, 2025
99628b1
Revert to older implementation
jerelmiller Sep 11, 2025
8314160
Inline deepMerge
jerelmiller Sep 11, 2025
fcc7abe
Fix missing default from change to shared function
jerelmiller Sep 11, 2025
8283dfd
Fix most cases of merging cache with streamed chunks
jerelmiller Sep 11, 2025
eb9e0ba
Fix issue with non-zero lists sent with defer chunk
jerelmiller Sep 11, 2025
8ee410e
Add additional test to check non-zero length array in defer chunk
jerelmiller Sep 11, 2025
9dc3d43
Add failing test for merging cache data on defer chunk
jerelmiller Sep 11, 2025
ffae390
Fix the failing test
jerelmiller Sep 11, 2025
20a70d2
Rename property
jerelmiller Sep 11, 2025
f778b85
Add comment
jerelmiller Sep 11, 2025
1efd97a
Update comment
jerelmiller Sep 11, 2025
c167c14
it -> test
jerelmiller Sep 11, 2025
7dd0199
Use shared schema
jerelmiller Sep 11, 2025
eac51b6
Add cache tests for defer20220824 stream
jerelmiller Sep 11, 2025
8f15609
Update stream tests to better handle React 18/19 differences
jerelmiller Sep 11, 2025
4a75420
Simplify merge function
jerelmiller Sep 11, 2025
107af9d
Add missing args for friendList in alpha2 schema
jerelmiller Sep 11, 2025
309e030
Update useSuspenseQuery tests to be more friendly between react versions
jerelmiller Sep 11, 2025
2e8dd81
Add useQuery stream tests for GraphQL17Alpha9Handler
jerelmiller Sep 12, 2025
4f3494f
Add useQuery stream tests for Defer20220824Handler
jerelmiller Sep 12, 2025
c785cc5
Add stream tests for useBackgroundQuery
jerelmiller Sep 12, 2025
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
17 changes: 14 additions & 3 deletions .api-reports/api-report-incremental.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,27 +25,38 @@ namespace Defer20220824Handler {
return: Defer20220824Handler.Chunk<Record<string, unknown>>;
}
// (undocumented)
type IncrementalDeferPayload<TData = Record<string, unknown>> = {
data?: TData | null | undefined;
type IncrementalDeferResult<TData = Record<string, unknown>> = {
data?: TData | null;
errors?: ReadonlyArray<GraphQLFormattedError>;
extensions?: Record<string, unknown>;
path?: Incremental.Path;
label?: string;
};
// (undocumented)
type IncrementalResult<TData = Record<string, unknown>> = IncrementalDeferResult<TData> | IncrementalStreamResult<TData>;
// (undocumented)
type IncrementalStreamResult<TData = Array<unknown>> = {
errors?: ReadonlyArray<GraphQLFormattedError>;
items?: TData;
path?: Incremental.Path;
label?: string;
extensions?: Record<string, unknown>;
};
// (undocumented)
type InitialResult<TData = Record<string, unknown>> = {
data?: TData | null | undefined;
errors?: ReadonlyArray<GraphQLFormattedError>;
extensions?: Record<string, unknown>;
hasNext: boolean;
incremental?: ReadonlyArray<IncrementalResult<TData>>;
};
// (undocumented)
type SubsequentResult<TData = Record<string, unknown>> = {
data?: TData | null | undefined;
errors?: ReadonlyArray<GraphQLFormattedError>;
extensions?: Record<string, unknown>;
hasNext: boolean;
incremental?: Array<IncrementalDeferPayload<TData>>;
incremental?: Array<IncrementalResult<TData>>;
};
// (undocumented)
interface TypeOverrides {
Expand Down
2 changes: 1 addition & 1 deletion .api-reports/api-report-utilities_internal.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -449,7 +449,7 @@ export type VariablesOption<TVariables extends OperationVariables> = {} extends

// Warnings were encountered during analysis:
//
// src/utilities/internal/getStoreKeyName.ts:88:1 - (ae-forgotten-export) The symbol "storeKeyNameStringify" needs to be exported by the entry point index.d.ts
// src/utilities/internal/getStoreKeyName.ts:89:1 - (ae-forgotten-export) The symbol "storeKeyNameStringify" needs to be exported by the entry point index.d.ts

// (No @packageDocumentation comment for this package)

Expand Down
8 changes: 8 additions & 0 deletions .changeset/six-islands-drum.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
"@apollo/client": minor
---

Add support for the `@stream` directive on both the `Defer20220824Handler` and the `GraphQL17Alpha2Handler`.

> [!NOTE]
> The implementations of `@stream` differ in the delivery of incremental results between the different GraphQL spec versions. If you upgrading from the older format to the newer format, expect the timing of some incremental results to change.
8 changes: 4 additions & 4 deletions .size-limits.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"import { ApolloClient, InMemoryCache, HttpLink } from \"@apollo/client\" (CJS)": 44206,
"import { ApolloClient, InMemoryCache, HttpLink } from \"@apollo/client\" (production) (CJS)": 39060,
"import { ApolloClient, InMemoryCache, HttpLink } from \"@apollo/client\"": 33462,
"import { ApolloClient, InMemoryCache, HttpLink } from \"@apollo/client\" (production)": 27490
"import { ApolloClient, InMemoryCache, HttpLink } from \"@apollo/client\" (CJS)": 44194,
"import { ApolloClient, InMemoryCache, HttpLink } from \"@apollo/client\" (production) (CJS)": 39041,
"import { ApolloClient, InMemoryCache, HttpLink } from \"@apollo/client\"": 33526,
"import { ApolloClient, InMemoryCache, HttpLink } from \"@apollo/client\" (production)": 27519
}
6 changes: 6 additions & 0 deletions src/__tests__/__snapshots__/exports.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -357,15 +357,21 @@ Array [
"ObservableStream",
"actAsync",
"addDelayToMocks",
"asyncIterableSubject",
"createClientWrapper",
"createMockWrapper",
"createOperationWithDefaultContext",
"enableFakeTimers",
"executeSchemaGraphQL17Alpha2",
"executeSchemaGraphQL17Alpha9",
"executeWithDefaultContext",
"friendListSchemaGraphQL17Alpha2",
"friendListSchemaGraphQL17Alpha9",
"markAsStreaming",
"mockDefer20220824",
"mockDeferStreamGraphQL17Alpha9",
"mockMultipartSubscriptionStream",
"promiseWithResolvers",
"renderAsync",
"renderHookAsync",
"resetApolloContext",
Expand Down
43 changes: 43 additions & 0 deletions src/cache/inmemory/__tests__/cache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1042,6 +1042,49 @@ describe("Cache", () => {
});
}
);

it("does not write @stream directive as part of the cache key", () => {
const cache = new InMemoryCache();

cache.writeQuery({
data: {
list: [{ __typename: "Item", id: "1", value: 1 }],
},
query: gql`
query {
list @stream(initialCount: 1) {
id
value
}
}
`,
});

expect(cache.extract()).toStrictEqualTyped({
ROOT_QUERY: {
__typename: "Query",
list: [{ __ref: "Item:1" }],
},
"Item:1": { __typename: "Item", id: "1", value: 1 },
});

// We should be able to read the list without the `@stream` directive and
// get back results
expect(
cache.readQuery({
query: gql`
query {
list {
id
value
}
}
`,
})
).toStrictEqualTyped({
list: [{ __typename: "Item", id: "1", value: 1 }],
});
});
});

describe("writeFragment", () => {
Expand Down
Loading
Loading