How to map a defer result?
Closed this issue · 2 comments
schleumer commented
I have a hypothetical fetcher:
val usersCount = Fetcher((repo: Repo, ids: Seq[Long]) ⇒ repo.users.countByParent(ids))
this will return me a Seq[Count]
where case class Count(id: Long, count: Long)
there's a way that i can make this field:
Field("usersCount", UsersCountType, resolve = c ⇒ usersCount.defer(c.value.id))
becomes something like this:
Field("usersCount", LongType, resolve = c ⇒ usersCount.defer(c.value.id).map(_.count))
Sorry if this is the wrong place to ask this...
OlegIlyenko commented
You just need to use explicitly a DeferredValue
which has a map method (which is defined on the Action
):
Field("usersCount", LongType, resolve = c ⇒ DeferredValue(usersCount.defer(c.value.id)).map(_.count))
I probably will add it in the docs. This question was asked quite often recently :)
schleumer commented
This is simply beautiful, thanks! This couldn't be easier. Worked really great.