How to handle array of objects which may or may not exist? #7756
Replies: 1 comment 2 replies
-
I'm going to ignore the wrapper approach for now, that's not really ideal and I think you can accomplish what you're after with a resolver change and no schema change. I think what you're looking to do is throw an error for a single list item without blowing up the whole list. You can do that, you just need to throw an error from one of the field resolvers on the type of the list item. If you return Here's a sandbox which should demonstrate what I mean. In the example, I provide 3 items in the list:
Notice for #2, I can throw an error from the Run query: {
things {
id
}
} It's also worth mentioning that the |
Beta Was this translation helpful? Give feedback.
-
I'm having some problems fixing up an existing schema made by someone else and I'm not sure how to solve one particular problem involving data corruption.
I have some models on one service that have a data structure like
however some of the objects referenced by
otherObjectIDs
do not exist. (Let's assume here that I cannot fix the database)Currently this is implemented as
and the resolver substitutes
null
in place for missing objects.This works, but the user gets no error for it which can sometimes result in an entire array of
null
values if something fails for a different reason which is a problem.I have discovered that I can work around this in an extremely ugly way by doing something like
and the resolver
ObjectTwoWrapper.object
is invoked once per ID in the list and if it throws an error that gets sent to the user correctlyHowever this is a breaking API change! How do I get the same behaviour without changing my API?
Beta Was this translation helpful? Give feedback.
All reactions