0

在派生对象类型时,我想使用 Sangria 的 AddFields 方法添加一个字段。我不知道如何填写参数“resolve =”有人可以帮助我吗?

给定的是实体交付和系统。我派生了对象类型 SystemD4S。现在我想在派生对象类型中添加一个类型为 SystemD4S 的字段“systemObject”以进行传递。不知道如何填写参数“resolve =”

case class Delivery (
                     docid: String,
                     override val docType: String = Doctype.DELIVERY,
                     system: String,
                     status: String,
                     items: List[DeliveryItem],
                     deleted: Boolean
                     ) extends EntityItemCollection {
  def getBusinessKey: String = s"$docid::$docType::$system"
}

case class System(id: String, company: String)

val SystemD4S = deriveObjectType[D4sEntityRepo, System](
    ObjectTypeDescription("system"))

val DeliveryD4S = deriveObjectType[D4sEntityRepo, Delivery](
    ObjectTypeDescription("delivery"),
    AddFields(Field("systemObject", SystemD4S, resolve = c => enitiesD4S.deferRel()))
  )
4

1 回答 1

0

resolve 是 type 的函数Context[Ctx, Val] ⇒ Action[Ctx, Res]

因为deriveObjectType[D4sEntityRepo, Delivery], 你的Ctxis D4sEntityRepo, ValisDeliveryResisSystemD4S

现在要enitiesD4S在解析函数中获取实例,您可以使用c.ctx.

val DeliveryD4S = deriveObjectType[D4sEntityRepo, Delivery](
    ObjectTypeDescription("delivery"),
    AddFields(Field("systemObject", SystemD4S, resolve = c => c.ctx.deferRel()))
  )

希望这可以帮助。

于 2019-08-08T08:20:55.407 回答