Sangria-graphql:传递derivedInputObjectType作为变异参数时出错

时间:2017-08-20 16:16:00

标签: scala graphql sangria

我有以下包含选项字段的案例类:

case class BusinessUserRow(id: String, firstName: Option[String], lastName: Option[String], email: Option[String])

我正在尝试为Business User Object创建一个inputType对象

val BusinessUserInputType =
    deriveInputObjectType[BusinessUserRow](
      InputObjectTypeName("input"),
      InputObjectTypeDescription("A Business user")
    )

我希望将此BusinessInputObject作为参数传递给addBusinessUser变种

  val businessUserInputArg = Argument("input", BusinessUserInputType)

val Mutation = ObjectType("Mutation", fields[RepoContext, Unit](
    Field("addBusinessUser", BusinessUserType,
      arguments = businessUserInputArg :: Nil,
      resolve = c ⇒ c.ctx.BusinessUserRepo.create(c.arg(businessUserInputArg)))))

但是我得到以下编译错误:

Type dao.Tables.BusinessUserRow @@ sangria.marshalling.FromInput.InputObjectResult cannot be used as an input. Please consider defining an implicit instance of `FromInput` for it.
[error]   val businessUserInputArg = Argument("input", BusinessUserInputType)

但BusinessRow中的所有字段都是标量值。我不明白是什么导致了这个问题。我有没有看到的东西?

2 个答案:

答案 0 :(得分:2)

为了反序列化BusinessUserRow案例类中的输入,您需要提供FromInput[BusinessUserRow]类型类的实例。你可以在这里找到更多的文档:

http://sangria-graphql.org/learn/#frominput-type-class

例如,如果你是使用spray-json,那么你需要为JsonFormat定义BusinessUserRow

答案 1 :(得分:0)

谢谢!只是添加这一行解决了我的问题:

implicit val businessUserFormat = Json.format[BusinessUserRow]