pgutkowski / KGraphQL

Pure Kotlin GraphQL implementation

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

LocalDate coercion issue

shamresh opened this issue · comments

Hi,

I am getting the following error:

{
  "errors": {
    "message": "Caught ExecutionException: Failed to coerce {manufacturer:Joe Bloggs,name:Front bumper,oem:true,addedDate:2001-09-01} as NewPart"
  }
}

If I leave out addedDate then the mutation works as expected.

My code is as follows:

   stringScalar<LocalDate> {
            serialize = { date ->
                logger.info("Serialization of date: $date")
                date.toString() }
            deserialize = { dateString ->
                logger.info("Deserialization of custom scalar type: $dateString")
                LocalDate.parse(dateString) }
            description = "Date in format yyyy-mm-dd"
        }

and

 mutation("addPart") {
            description = "Adds a new part in the parts inventory database"
            resolver { newPart: NewPart ->
                val (name, manufacturer, addedDate, oem) = newPart
                val part = Part(name, manufacturer, LocalDate.now(), oem)
                val repository by kodein.instance<PartsRepository>()

                repository.addPart(part)
            }
        }

       inputType<NewPart>(){
        }

This library is amazingly written.

Hi @shamresh!

You issue has been solved by @jeggy PR today, see #46. I've added unit test for your use case:

.

Expect release 0.3.1 today with #46 included.

Hi, where can I find release 0.3.1?
Thanks for all the great work.