Skip to content
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

Partial Resolvable Results #2

Open
xsc opened this issue Oct 11, 2016 · 0 comments
Open

Partial Resolvable Results #2

xsc opened this issue Oct 11, 2016 · 0 comments

Comments

@xsc
Copy link
Owner

xsc commented Oct 11, 2016

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.

@xsc xsc added the discussion label Oct 11, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant