question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

"Type ... cannot be used as an input" compilation error

See original GitHub issue

I got compilation errors trying to implement simple mutation api. Possibly I’m doing something wrong but I wasn’t able to figure out what exactly.

Error:

Error:(18, 83) Type sangria.util.tag.@@[me.scf37.graphql1.PermissionInput,sangria.marshalling.FromInput.InputObjectResult] cannot be used as an input. Please consider defining an implicit instance of `FromInput` for it.
   implicit val MutationApiType = deriveContextObjectType[Ctx, MutationApi, Unit] {_.mutationApi}

Error:(18, 83) not enough arguments for method createWithoutDefault: (implicit fromInput: sangria.marshalling.FromInput[sangria.util.tag.@@[me.scf37.graphql1.PermissionInput,sangria.marshalling.FromInput.InputObjectResult]], implicit res: sangria.schema.ArgumentType[sangria.util.tag.@@[me.scf37.graphql1.PermissionInput,sangria.marshalling.FromInput.InputObjectResult]])sangria.schema.Argument[res.Res].
Unspecified value parameters fromInput, res.
   implicit val MutationApiType = deriveContextObjectType[Ctx, MutationApi, Unit] {_.mutationApi}

Code:

case class Permission(id: String, name: String, description: String)
case class PermissionInput(name: String, description: String)
case class Ctx(mutationApi: MutationApi)

trait MutationApi {
    @GraphQLField
    def permission(permission: PermissionInput): Permission = ???
}

object Main {
   implicit val PermissionType = deriveObjectType[Ctx, Permission]()
   implicit val PermissionInputType = deriveInputObjectType[PermissionInput]()
   implicit val MutationApiType = deriveContextObjectType[Ctx, MutationApi, Unit] {_.mutationApi}
}

Environment:

scalaVersion := "2.12.1"
Oracle 64-Bit Java "1.8.0_112"
Tried Sangria 1.0.0-RC5 and 4fe3952
sbt 0.13.13

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
scf37commented, Jan 25, 2017

It worked for me. In general, PLEASE consider adding scaladoc at least to public API. All that functional code with heaps of implicits is damn hard to decipher.

2reactions
jonascommented, Jan 12, 2017

When using macros to derive context objects with methods you need to also declare an implicit JSON decoder for each of the input type associated with the method arguments. This is what is hinted in:

Please consider defining an implicit instance of `FromInput`

If you are using Spray JSON this would be something like:

object Main extends spray.json.DefaultJsonProtocol {
   implicit val PermissionType = deriveObjectType[Ctx, Permission]()
   implicit val PermissionInputType = deriveInputObjectType[PermissionInput]()
   implicit val PermissionInputJson = jsonFormat2(PermissionInput)
   implicit val MutationApiType = deriveContextObjectType[Ctx, MutationApi, Unit] {_.mutationApi}
}
Read more comments on GitHub >

github_iconTop Results From Across the Web

C++ input compilation error [closed] - Stack Overflow
I was trying to make a C++ input file on Ideone.com, an online compiler. The program is meant to take in a users...
Read more >
How to Handle the Incompatible Types Error in Java - Rollbar
The Java incompatible types error happens when a value assigned to a variable or returned by a method is incompatible with the one...
Read more >
function that returns 'auto' cannot be used before it is defined"?
This means “I want the compiler to deduce the return type (but I'm not giving any clues yet).” If you try to call...
Read more >
Compilation Errors - Constants, Enumerations and Structures
Compilation Errors ; 285. Structures and arrays cannot be used as input variables ; 286. Const specifier is not valid for constructor/destructor ;...
Read more >
Chapter 4. Types, Values, and Variables - Oracle Help Center
Strong static typing helps detect errors at compile time. The types of the Java programming language are divided into two categories: primitive types...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found