Objects as arguments in mutations

207 views
Skip to first unread message

Carlos Dañel Ferreyra

unread,
Aug 18, 2017, 11:38:16 AM8/18/17
to sangria-graphql
I'm trying to define a mutation like the following:

case class Department(name: String)

trait Mutation {
  @GraphQLField
  def createDepartment(department: Department): Department = {
    // Not implemented
    department
  }
}

val mutation: Mutation = new Mutation {}

val mutationType: ObjectType[Unit, Unit] = deriveContextObjectType[Unit, Mutation, Unit](_ => mutation)

And I can't find my way pass this error:

Error:(96, 93) Type ssor.model.package.Department @@ sangria.marshalling.FromInput.InputObjectResult cannot be used as an input. Please consider defining an implicit instance of `FromInput` for it.
    val mutationType: ObjectType[Unit, Unit] = deriveContextObjectType[Unit, Mutation, Unit](_ => mutation)

Could anyone give any pointers on way I'm missing?
I couldn't even figure out if I'm missing some implicits or if this is even supported at all to pass objects as arguments in sangria.

Thanks,
Carlos


Oleg Ilyenko

unread,
Aug 18, 2017, 11:42:23 AM8/18/17
to sangria-graphql
you need to define an implicit `InputObjectType` for `Department` and some means to deserialize it from JSON (for instance, if you are using spray-json you need to define a `JsonFormat` for it)

Carlos Dañel Ferreyra

unread,
Aug 18, 2017, 1:40:11 PM8/18/17
to sangria-graphql
I added:

implicit val departmentJF: RootJsonFormat[Department] = jsonFormat1(Department)

implicit val inputDepartmentType: InputObjectType[Department] = deriveInputObjectType[Department](
      InputObjectTypeName("Department"),
      InputObjectTypeDescription("A department"))

Yet the error insists.

I'll try to debug the output of -Xlog-implicits to see what else I'm missing.
Reply all
Reply to author
Forward
0 new messages