Allow getFieldValue to read from foreign Reference objects. #5651
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.
The
getFieldValue(fieldName)
helper function was introduced in #5617 for reading fields from the currentStoreObject
duringread
functions.This commit adds a second parameter to
getFieldValue
,foreignRef
, which is an optionalReference
. WhenforeignRef
is provided,getFieldValue
will read the specified field from theStoreObject
identified by theforeignRef
, instead of reading from the currentStoreObject
.In either case,
getFieldValue
reads an existing value from the cache, without invoking anyread
functions, so you cannot usegetFieldValue
to set up expensive (and potentially cyclic) chains ofread
functions.With this new ability to read fields from arbitrary
Reference
objects,read
functions can explore the entire reachable cache without having to callcache.readQuery
. The beauty of this system is that every field reading operation requires a function call (getFieldValue
), which allows the result caching system to know which fields were read from which entities, so future changes to those fields can properly invalidate any cached results that involved the originalread
function.I recommend reading through the included tests to get a concrete sense for how everything works.