-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Deprecate partial
and ensure its correctness. Fix type of data
in ApolloQueryResult
#12333
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
Conversation
🦋 Changeset detectedLatest commit: a8da500 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: |
size-limit report 📦
|
@@ -1081,9 +1080,7 @@ Did you mean to call refetch(variables) instead of refetch({ variables })?`, | |||
// because the query may be using the @nonreactive directive, and we want to | |||
// save the the latest version of any nonreactive subtrees (in case | |||
// getCurrentResult is called), even though we skip broadcasting changes. | |||
if (lastError || !result.partial || this.options.returnPartialData) { |
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 cache.diff
is returning null
for empty results or incomplete data, we no longer need this check as the value reported to this function is the correct value.
✅ Deploy Preview for apollo-client-docs ready!
To edit notification comments on pull requests, go to your Netlify site configuration. |
@@ -517,10 +517,7 @@ export class InternalQueryReference<TData = unknown> { | |||
|
|||
this.result = result; | |||
this.promise = | |||
( | |||
result.data && | |||
(!result.partial || this.watchQueryOptions.returnPartialData) |
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.
Similarly, we don't need this check anymore since result.data
will always be null
if there is no data to report.
@@ -141,7 +141,7 @@ export type { QueryOptions as PureQueryOptions }; | |||
export type OperationVariables = Record<string, any>; | |||
|
|||
export interface ApolloQueryResult<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.
Eventually I'd like to make this type a bit smarter so that we can handle DeepPartial<TData>
when complete
is false
, but I'll leave that to a separate PR.
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.
👍
@@ -1345,7 +1345,7 @@ describe("client.watchQuery", () => { | |||
const { data } = await queryStream.takeNext(); | |||
const fragmentObservable = client.watchFragment({ | |||
fragment, | |||
from: data.currentUser, | |||
from: data!.currentUser, |
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 know it's the correct thing to do, but this will be so annoying for our users :sad:
"@apollo/client": major | ||
--- | ||
|
||
Fix type of `data` property on `ApolloQueryResult`. Previously this field was non-optional, non-null `TData`, however at runtime this value could be set to `undefined`. This field is now reported as `TData | undefined`. |
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.
Maybe we should call out here that this might need quite a lot of code adjustments?
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.
yeah, this will be a huge pain, and somehow counter-intuitive at first glance. But ultimately it is the way to go. I just wish we had a way to tell Apollo "I pinky-promise I will never use partial result in my entire project", and then the typing (and actual value) can never be undefined
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.
@PowerKiKi I'm hoping that we can get #12350 in there which would help this situation a lot since we can narrow the type of data
based on whether its empty, partial, or complete. We are bike shedding on the name, but will likely get this in there.
@@ -141,7 +141,7 @@ export type { QueryOptions as PureQueryOptions }; | |||
export type OperationVariables = Record<string, any>; | |||
|
|||
export interface ApolloQueryResult<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.
👍
complete: true, | ||
partial: false, |
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.
This feels like a blocker for a 4.0 release to me.
Do we track somewhere that this has to be done as a follow-up before we can release a 4.0?
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.
Created #12345 to call this out
src/react/hooks/useQuery.ts
Outdated
@@ -733,7 +736,7 @@ export function toQueryResult<TData, TVariables extends OperationVariables>( | |||
observable: ObservableQuery<TData, TVariables>, | |||
client: ApolloClient<object> | |||
): InternalQueryResult<TData, TVariables> { | |||
const { data, partial, ...resultWithoutPartial } = result; | |||
const { data, complete, partial, ...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.
I'm actually a bit confused here (unrelated to this PR) - why do we have a returnPartialData
option, but neither complete
nor partial
on the useQuery
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.
Agreed. As discussed in person, this will be done in a separate PR so we can add it to all the hooks.
partial
to complete
and only set it when returnPartialData
is true
partial
and ensure its correctness. Fix type of data
in ApolloQueryResult
Closes #12332
This change aims to bring more consistency to the emitted results from the core API with the following changes:
partial
flag a non-optional property that is now emitted with everyApolloQueryResult
partial
flag. A followup solution will be provided with [4.0] Add a new status enum toApolloQueryResult
that describes the state of data #12344data
property on the emitted result instead of omitting it when it would otherwise beundefined
. This aligns the runtime behavior with the TypeScript type which specifiesdata
as a non-optional property.ApolloQueryResult
to specifydata
asTData | undefined
to align it with the runtime behavior where an undefined result can be emitted from the core API.