@apollo/client@4.3.0-alpha.3
Pre-releaseMinor Changes
-
#13324
0abd8deThanks @jerelmiller! - Fix the accuracy ofdataStatein complex incremental streaming scenarios, especially when combined withreturnPartialData: true.Prior to this change, all intermediate chunks used for both
@deferand@streamdirectives returned adataStateofstreaming, regardless of whether the actual data shape fit the definition of thestreamingdata state. Thestreamingdata state represents an incomplete incremental response where the only holes in the data occur at@deferboundaries.Let's use the following example of where the previous
dataStatefell down when combined withreturnPartialData.query GreetingQuery { greeting { message ... @defer { recipient { name email } } } }
- Scenario 1: partial data inside a
@deferboundary written to the cache
Let's say the cache contained the following partial data:
{ greeting: { __typename: "Greeting", recipient: { __typename: "Person", name: "John Doe", }, }, };
After the first chunk arrives from the server, the data looks like the following:
{ greeting: { __typename: "Greeting", message: "Hello, John", recipient: { __typename: "Person", name: "John Doe", }, }, };
This data is not
completebecauserecipient.emailis missing. This data is also notstreamingbecause the data requirements in the@deferboundary are partially fulfilled due to the existence ofrecipient. This could lead to runtime crashes onrecipient.emailif you use the existence ofrecipientto detect whether data in the@deferboundary has streamed in or not. This change now accurately reports this aspartialto ensure the field is marked as a partial field inrecipient.- Scenario 2: partial data written to the cache that fulfills the data requirements of the
@deferboundary
Let's say the cache contained the following partial data:
{ greeting: { __typename: "Greeting", recipient: { __typename: "Person", name: "John Doe", email: "john@example.com", }, }, };
After the first chunk arrives from the server, the data looks like the following:
{ greeting: { __typename: "Greeting", message: "Hello, John", recipient: { __typename: "Person", name: "John Doe", email: "john@example.com", }, }, };
In this case, the combination of the first chunk and the partial data in the cache now fulfills the data requirements of the query. Even though the server is still streaming data (
NetworkStatus.streaming), we can report this asdataState: "complete"since it is safe to access data on all fields.This change also means
@streamqueries by definition fulfill the data requirements of the query after the first chunk arrives since@streamoperates on lists and contains no data holes.@streamqueries now accurately reportdataStateascompleteorpartial, depending on whether the list mixes partial data with streamed list items.As a result of this change, some cases where you'd previously see
dataStatereported as"streaming"are now reported aspartialorcomplete.If you use
dataStateto determine whether an incremental request is still in-flight, please usenetworkStatusinstead to check forNetworkStatus.streaming.dataStateis type narrowing feature and not intended to report the network status. - Scenario 1: partial data inside a
Patch Changes
-
#13324
0abd8deThanks @jerelmiller! - Fix an issue where fieldreadfunctions were not applied to intermediate results while streaming@deferresponses.cache.diffran thereadfunctions, but the transformed values were only applied to the emitted result when the updated cache result was considered complete. Intermediate chunks whose only holes were at@deferboundaries now correctly return the result of fieldreadfunctions.new InMemoryCache({ typePolicies: { Greeting: { fields: { message: { read: (message) => message.toUpperCase(), }, }, }, }, }); // query GreetingQuery { // greeting { // message // ... @defer { // recipient { name } // } // } // } // First chunk previously returned: // { greeting: { message: "Hello world" } } // // Now correctly returns while still streaming: // { greeting: { message: "HELLO WORLD" } }
-
#13324
0abd8deThanks @jerelmiller! - Fix an issue with@streamqueries when usingreturnPartialData: truewhere the streamed list was truncated after the first incremental chunk when the list contained partial cache data. The list is no longer truncated and partial list items are now retained as incremental chunks arrive. ThedataStateis now reported aspartialuntil the server has streamed enough of the list so that each list item fully satisfies the query.This change also updates
@streamqueries so that they reported withdataState: "completeinstead of"streaming"since it is safe to access all fields in the response.