caliban icon indicating copy to clipboard operation
caliban copied to clipboard

Add support for `@oneOf` inputs

Open kyri-petrou opened this issue 2 years ago • 0 comments

VERY early draft for adding support for the @oneOf inputs, just to discuss whether we're on the right track. See current version of the RFC here

Some of the assumptions I made:

  1. We probably want to require an annotation to mark an input sealed trait as a oneOf. I think that makes sense since the spec on @oneOf is very strict, so it's very unlikely that these sealed traits will be used for any return types
  2. Since in Scala 3 we control derivation, I enforced the checks that the sealed trait is a valid @oneOf via macros. I think it's nicer UX if we give compile-time errors instead of runtime ones for invalid types. However, in Scala 2 we don't control the derivation so we have to enforce these checks during runtime. I understand if we want to unify the validation, so I'm happy to remove the macros
  3. I couldn't find anything in the spec (might have missed it though) but I assumed we don't want to mark inputs as @oneOf if they have only 1 field (kind of defeats the purpose?)

TODO:

  • [x] Add validations for @oneOf inputs in Validator (both against the Schema & user inputs)
  • [x] Add tests where @oneOf inputs are a mix of input objects and Scalars
  • [ ] Add documentation
  • [ ] Discuss on what we should do with the client

kyri-petrou avatar Aug 21 '23 17:08 kyri-petrou