-
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
Don't throw on missing results with cache.diff
and other changes
#12304
Conversation
🦋 Changeset detectedLatest commit: 3313ca3 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 📦
|
✅ Deploy Preview for apollo-client-docs ready!
To edit notification comments on pull requests, go to your Netlify site configuration. |
db5aea0
to
8a26e33
Compare
@@ -551,7 +551,7 @@ describe("ObservableQuery", () => { | |||
{ | |||
const result = await stream.takeNext(); | |||
|
|||
expect(result.data).toEqual({}); | |||
expect(result.data).toEqual(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.
This is one great benefit of this change. We report this type as TData | undefined
, yet at times we returned an empty object at runtime. With the change in place, we now properly get undefined
.
294f707
to
5f341c1
Compare
@@ -710,9 +712,11 @@ describe("cache-and-network", function () { | |||
await observable.setVariables({ id: "2" }); | |||
|
|||
await expect(stream).toEmitValue({ | |||
data: {}, | |||
data: 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.
Much better 🎉. It was always odd that we'd get back an empty object when returnPartialData
was false
.
Add a doc block to |
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.
Some small things, but once those have been tackled: ✅
This PR changes
cache.diff
to returnnull
instead of throwing aMissingFieldError
whenreturnPartialData
isfalse
. This better aligns with some of the other cache read APIs, such asreadFragment
where incomplete results returnnull
instead of throwing errors.This should allow us to update some of our usages of
cache.diff
throughout the codebase where we setreturnPartialData
totrue
. I believe this was done to avoid havingcache.diff
throw in the case of missing data. Ideally we only need to setreturnPartialData
when specified by the user (subject to future exploration and testing).This change better aligns with some of the other cache read operations that return
null
with partial results, such ascache.readFragment()
.Some other changes/improvements in this PR:
Cache.DiffResult<TData>
is now a bit smarter and behaves closer touseFragment
where it now returns a union to handle whencomplete
istrue
orfalse
. This should give better type safety, especially whencomplete
is false since the behavior today returnsTData
instead ofDeepPartial<TData>
in this case.missing
property onCache.DiffResult
is now eitherundefined
or an instance ofMissingFieldError
. The array was removed as this information is all embedded in theMissingFieldError
instance itself.