Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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
[docs] Update cache-configuration keyFields docs #11778
base: main
Are you sure you want to change the base?
[docs] Update cache-configuration keyFields docs #11778
Changes from 2 commits
4499256
cbb325a
9b57a7a
103f8c6
2e28818
523c4fb
24a611c
d0516a8
396a27b
7483ab7
0c33efd
File filter
Filter by extension
Conversations
Jump to
There are no files selected for viewing
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 a
keyFields
function, returningfalse
would indicate that this particular instance of a type shouldn't be normalized and instead embedded in the parent, correct?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.
@adamesque thats correct! Here is a test that demonstrates returning
false
from akeyFields
function. You can see the cache is non-normalized:apollo-client/src/cache/inmemory/__tests__/policies.ts
Lines 5543 to 5622 in 8bc7d4d
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.
Nice! Million-dollar question — is that true for any falsy value? It seems like it based on this or this?
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 think thats accurate, but I'd like to verify myself before giving a definitive yes. Intuitively it would make sense that if we don't get an identifier for a particular store object that we'd consider it non-normalized, but again, let me check to make sure thats accurate.
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.
@adamesque just tried this out and I can confirm it seems that any falsey value will be treated as
false
and won't normalize the record.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.
Great, thanks! I don't know exactly why
ReturnType<IdGetter>
is important to include in the return type union but it would definitely be clearer if it was justKeySpecifier | 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.
I agree! I'll see if we can simplify that type.
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.
ReturnType<IdGetter>
does addundefined
(which is unfortunate because we probably want people to be more explicit withfalse
) andstring
, which is important - thekeyFn
function can not only return an array of field names, but also directly an identifier (although I'd advise against using that in many situations and leave the field-reading to the InMemoryCache instead).I probably wouldn't change the type around to remove
undefined
here, since probably a lot of people just skip thereturn
call in some conditions and that would break a lot of code bases for no very good reason.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's leave this the same as it was before. Perhaps another bullet point stating that
keyFields: false
disables normalization? It doesn't have anything to do with singletons though.