-
Notifications
You must be signed in to change notification settings - Fork 2.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add a dataState
enum to ApolloQueryResult
#12350
base: release-4.0
Are you sure you want to change the base?
Conversation
🦋 Changeset detectedLatest commit: e05d975 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
|
commit: |
* - `complete`: `data` is a fully satisfied query result fulfilled | ||
* either from the cache or network. | ||
*/ | ||
dataState: "complete"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let the bike shedding commence!
✅ Deploy Preview for apollo-client-docs ready!
To edit notification comments on pull requests, go to your Netlify site configuration. |
size-limit report 📦
|
| { | ||
// Defer to the passed in type to properly type the `@defer` fields. | ||
data: T; | ||
dataState: "hasNext"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not super in love with this name, but its been difficult to come up with something that doesn't sound the same as partial
. The difference here is that partial
is meant to describe a partial cache hit where some fields are missing, where hasNext
is a @defer
query that hasn't fully streamed in the full data set.
Other options considered:
streaming
pending
} | ||
| { | ||
// Defer to the passed in type to properly type the `@defer` fields. | ||
data: T; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In the case of hasNext
, I've left the T
type alone. GraphQL Codegen will generate a type which includes a union on all deferred fields that handles the "missing" holes in the type.
The biggest downside to this is that the complete
case also returns the type as-is which means the user will still have to check the deferred fields to ensure they are there to satisfy TypeScript. Ideally we could unwrap that type a bit, but this may prove to be challenging.
I welcome any thoughts here.
// Even though `data` didn't change, the `dataStatus` is updated to reflect | ||
// that the full result has been stremed in so we expect another render | ||
// value. | ||
await expect(stream).toEmitApolloQueryResult({ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Now that we are reporting the dataStatus
enum with a proper value, I think it is necessary to emit another value that reports the dataStatus
as complete
, even though the data
property itself didn't change since the deferred fragment was masked.
d04f0bf
to
e05d975
Compare
@@ -734,9 +736,9 @@ export function toQueryResult<TData, TVariables extends OperationVariables>( | |||
observable: ObservableQuery<TData, TVariables>, | |||
client: ApolloClient<object> | |||
): InternalQueryResult<TData, TVariables> { | |||
const { data, partial, ...resultWithoutPartial } = result; | |||
const { data, partial, dataState, ...resultWithoutPartial } = result; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We will expose this property in a separate PR so we can add support for it to all hooks.
Closes #12344
Closes #12345
Adds a new
dataState
enum returned fromApolloQueryResult
that describes the state of thedata
property.ApolloQueryResult
is now a discriminated union that better describes the value ofdata
when in a particular state which provides additional type safety.This new enum is now able to track whether the is waiting for additional chunks when used with
@defer
which can be useful to determine whether the full result has streamed in or not.