0

Let me explain:

I am using Gson as deserializer, MongoDB as storage and the newly Spring GraphQL

Let's say I have an object O in database with the fields:

A = 6
B = null

If the frontend send an update on the B field so I receive a JSON with only the B field with its value, so I receive O with:

B = 1

Then after deserialization, in Java my object O will have the following fields:

A = null
B = 1

Then, in MongoDB it will save:

A = null
B = 1

So the value of A will be overwritten by null, and we don't want that, the frontend only wanted to update the field B.

How do you solve that gracefully?

1 Answers1

0

There is no support for "patchable entities" right now in Spring GraphQL. While the null vs. "empty" values for a field are accessible in the JSON map directly, binding that to a Java object and tying that up with the data Repository story is a bigger challenge.

This is being discussed in this Spring GraphQL issue.

Brian Clozel
  • 56,583
  • 15
  • 167
  • 176
  • Thank you for your answer Brian ! Is there any workaround in Java for that ? Do we know when the Spring GraphQL team will implement patchable entities ? – Christophe Bouillaud Mar 11 '22 at 08:34