john
john

Reputation: 1075

Sangria-graphql: error when passing in derivedInputObjectType as an mutation argument

I have the following case class with option fields:

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

I am trying to create an inputType Object for Business User Object

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

and I want to pass this BusinessInputObject as an argument to a addBusinessUser mutation

  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)))))

But I get the following compilation error:

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)

But All fields in BusinessRow are scalar values. I don't understand what is causing the issue.Is there something I am not seeing?

Upvotes: 1

Views: 1283

Answers (2)

john
john

Reputation: 1075

thanks! just adding this line solved my problem:

implicit val businessUserFormat = Json.format[BusinessUserRow]

Upvotes: 0

tenshi
tenshi

Reputation: 26566

In order to deserialize the input in the BusinessUserRow case class, you need to provide an instance of FromInput[BusinessUserRow] type class. You can find more docs on it here:

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

So if you are, for instance, using spray-json, then you need to define JsonFormat for BusinessUserRow

Upvotes: 2

Related Questions