title: Combine multiple deferred values into a new deferred type in Sangria, GraphQL Implementation
body: <p>We have two endpoints (backend calls) which return different but relevant data types <code>XData</code> and <code>YData</code>. If an instance of <code>XData</code> exists with id <code>1</code>, then there must be an instance of <code>YData</code> with the same id <code>1</code>.</p>
  
  <p>We have created a fetcher for each data type <code>xFetcher</code> and <code>yFetcher</code>. These fetchers are used separately in our GraphQL query to fetch data from both endpoints, but for some use case we want to combine data retrieved from both of them using a specific id, e.g., <code>1</code>. This combination might not be a simple list append, as shown in the example below.</p>
  
  <p>As <code>XData</code> and <code>YData</code> are queried also separately in other parts of the query, we cannot simply merge these two resolvers into one, and we are trying to avoid doing multiple calls to the same endpoint if possible.</p>
  
  <p>I have created a simplified example for this use case. How can we return one deferred value combining data retrieved from two fetchers?</p>
  
  <pre><code>case class Ctx()
  case class XData(id: Int, a: Seq[String], b: String)
  case class YData(id: Int, a: Seq[String], c: String)
  case class Data(id: Int)
  
  val xFetcher = Fetcher((ctx: Ctx, ids: Seq[Int]) =&gt; Future {
    ids.map(id =&gt; XData(1, Seq.empty, "")) // Back end call to (endpoint X)
  })(HasId(_.id))
  
  val yFetcher = Fetcher((ctx: Ctx, ids: Seq[Int]) =&gt; Future {
    ids.map(id =&gt; YData(1, Seq.empty, "")) // Back end call to (endpoint Y)
  })(HasId(_.id))
  
  val GData = deriveObjectType[Ctx, Data](
    AddFields(
      Field("a",
        ListType(StringType),
        resolve = ctx =&gt; getA(ctx))
    )
  )
  
  def getA(ctx: Context[Ctx, Data]) = {
    val id = ctx.value.id
  
    // Here I should also get an instance of `YData` and return the
    // combination of the sequences `a` in both instances (xData, yData)
    val xData: XData = ??? //getDeferredXData()
    val yData: YData = ??? //getDeferredYData()
    val desiredOutput = xData.a ++ yData.a
  
    // I can get `a` from one instance but not both of them together
    DeferredValue({
      val xData = xFetcher.defer(id)
      // val yData = yFetcher.defer(id)
      // How can we combine both into one deferred value?
      xData
    }).mapWithErrors { data =&gt; (data.a, Vector.empty) }
  }
  </code></pre>
  
  <p>I haven't used Sangria much, so please excuse any unclear information related to <code>deferred resolvers</code> or <code>fetchers</code></p>