graphqlsangria

sangria query returning IntType


I'm trying to perform query agains my local graphql server defined in Sangria. I have mutation defined like this:

val Mutation = ObjectType(
"Mutation", fields[DAO, Unit](
  Field("addMovie", IntType,
    arguments = Title :: Genre :: IMDBLink :: Nil,
    resolve = ctx => ctx.ctx.addMovie(ctx.arg(Title) , ctx.arg(Genre), ctx.arg(IMDBLink)))
)

But when I'm trying to perform query against it, I'm receiving either Syntax error with this query: mutation addMovieQuery {addMovie(title: "asd", genre: "asasdqw", IMDBLink: "$imdbLink") {}}

Or Field 'addMovie' of type 'Int' must not have a sub selection when running query with id inside brackets


Solution

  • If a field returns an Int or any other scalar, as the error says that field cannot have a subselection. Scalars and enums are the "lead nodes" of a query, so you cannot select additional fields on them. Try this instead:

    mutation addMovieQuery {
      addMovie(title: "asd", genre: "asasdqw", IMDBLink: "$imdbLink")
    }