-
-
Notifications
You must be signed in to change notification settings - Fork 7
Partial Resolvable Results #2
Description
Sometimes, we already know part of the resolution result without doing any work, e.g. IDs or some child resolvables:
(defrecord Person [id]
data/Resolvable
...
data/Transform
(transform [_ result]
(assoc result :friends (->Friends id))))Since :friends only depends on the already knownid we don't really need to do any Person I/O if we want to apply the following projection:
{:friends [{:name projection/leaf}]}We could introduce a PartialResult protocol, allowing to expose such data:
(defrecord Person [id]
data/PartialResult
(partial-result [_]
{:id id, :friends (->Friends id)})
data/Resolvable
...
data/Transform
(transform [this result]
(merge result (data/partial-result this)))While it's possible to do some automatic merging of partial-result into the return value of transform I fear that this might create some surprises if done implicitly. Although, if we limit PartialResult to map values (which might be a reasonable thing to do) we can derive some very simple semantics à la: "If transform return a non-nil value, merge the partial result into it."
Another point of note is the fact that, if a Person does not exist, just using the partial result will not expose that fact (although the friend list will be empty). But I guess that if users are made aware of this caveat it shouldn't be a significant problem.