You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
transform method in DataFetcherResult is unable to modify/clear existing errors #2717
DataFetcherResult class has nice transform method that basically creates a new Builder from the existing object and allows us to modify its content using nice functional Consumer<Builder<T>>. We can replace data and localContext, however we cannot replace errors.
I found this problem in postprocessing in DGS framework. I wanted to add missing paths from context to errors if they were not set. I tried to use the transform method and I quickly found out that I cannot replace or modify errors list. Also, the list is immutable, so I cannot use a getter method and somehow modify it. What is more, errors stored there are also immutable.
However, it is still possible to manually recreate a result with replaced errors, for example like this:
But, if anything will be added to the implementation of DatafetcherResult in future, one needs to remeber to add it there to not lose any important info from the result.
My proposition is to add a simple clearErrors method to the existing implementation of Builder<T>. It is a new method, so backwards compatibility is not broken. The method basically clears a list underneath. When someone calls error(...) or errors(...) methods, new errors will be added to an empty list.
With that method it will be possible to use transform method for the described purpose.
Activity
bbakerman commentedon Feb 6, 2022
This makes lots of sense.
bbakerman commentedon Feb 6, 2022
Merged