Handling update and partial update

64 views
Skip to first unread message

Ros

unread,
Aug 22, 2018, 1:01:08 AM8/22/18
to sangria-graphql
Hi there,

The non required field can have one of following states:
  1. has a value
  2. is null (to reset or drop the field in database)
  3. does not exits (ignore the field)
However while parsing request json into Sangria Input type, I came across a problem.
For example: I have a input type for my update case:

lazy val BarInputType = InputObjectType[Bar](
  ...
List(
InputField("name"OptionInputType(StringType)),
    InputField("foo"OptionInputType(FooInputType)),
  ...

lazy val FooInputType = InputObjectType[Foo](...)

It works as expected for StringType Optional Input.
But, for foo, it treat the "null" and "value doesn't exist" both as None.

Is there any workaround for this? I need to receive null if null is provided and None if field doesn't exist.

Thanks in advance.

Oleg Ilyenko

unread,
Aug 28, 2018, 2:44:17 PM8/28/18
to sangria-graphql
In general, it should be possible to distinguish between null and undefined, even for input object fields. But it depends on the `FromInput` behavior. For example, if you are deserializing input object in a case class, then normally both null and undefined would result in None. Maybe you could demonstrate the issue with a small self-contained example? This would help a lot. You can use this snippet as a temple if you want: https://gist.github.com/OlegIlyenko/4068ad92e008cd4b5def1baa4ec3a67c
Reply all
Reply to author
Forward
0 new messages