Sangria-graphql:将 derivedInputObjectType 作为突变参数传递时出错
Sangria-graphql: error when passing in derivedInputObjectType as an mutation argument
我有以下情况 class 带有选项字段:
case class BusinessUserRow(id: String, firstName: Option[String], lastName: Option[String], email: Option[String])
我正在尝试为业务用户对象创建一个 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 中的所有字段都是标量值。我不明白是什么导致 issue.Is 有什么我没有看到?
为了反序列化 BusinessUserRow
案例 class 中的输入,您需要提供 FromInput[BusinessUserRow]
类型 class 的实例。您可以在此处找到更多文档:
http://sangria-graphql.org/learn/#frominput-type-class
因此,例如,如果您使用 spray-json,那么您需要为 BusinessUserRow
定义 JsonFormat
谢谢!只需添加此行即可解决我的问题:
implicit val businessUserFormat = Json.format[BusinessUserRow]
我有以下情况 class 带有选项字段:
case class BusinessUserRow(id: String, firstName: Option[String], lastName: Option[String], email: Option[String])
我正在尝试为业务用户对象创建一个 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 中的所有字段都是标量值。我不明白是什么导致 issue.Is 有什么我没有看到?
为了反序列化 BusinessUserRow
案例 class 中的输入,您需要提供 FromInput[BusinessUserRow]
类型 class 的实例。您可以在此处找到更多文档:
http://sangria-graphql.org/learn/#frominput-type-class
因此,例如,如果您使用 spray-json,那么您需要为 BusinessUserRow
JsonFormat
谢谢!只需添加此行即可解决我的问题:
implicit val businessUserFormat = Json.format[BusinessUserRow]