Skip to content
This repository has been archived by the owner on Jan 13, 2025. It is now read-only.

work with public methods parameters #15

Open
Mxrynd opened this issue Aug 20, 2021 · 1 comment
Open

work with public methods parameters #15

Mxrynd opened this issue Aug 20, 2021 · 1 comment

Comments

@Mxrynd
Copy link

Mxrynd commented Aug 20, 2021

Having toy type example

case class Book(name: String) {
    def timesName(n: Option[Int] = Some(42)) = name * n.get
}
object Book {
    implicit val bookSchema: Schema[Any, Book] = deriving.deriveSchemaInstance[Any, Book]
}

and 1 simple query returning default book I face some inconvenience moments.

  1. it works strangly with Option: calling timesName w/o n (which is valid)
query{
  book{
    name
    timesName
  }
}

leads to

{
  "data": null,
  "errors": [
    {
      "message": "java.util.NoSuchElementException: key not found: n"
    }
  ]
}

In addition it does not take default value into account
2) making n not optional, but just int leads generated schema to have parametr with !

To sum up: it would be nice to have input type/argument default value support and (ideally) treating fields with default values as optional during schema generating.
P.S. the same functionality in sangria is implemented with annotation, but unfortenutly it fails to make a field optional

@vigoo
Copy link
Contributor

vigoo commented Aug 20, 2021

Thanks for reporting this, I will take a look.
Using the provided default values may be tricky, have to check if it is possible both in Scala 2 and Scala 3 macros. We can always fall back to defining an annotation for it of course.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants