legumeinfo / graphql-server

A GraphQL server that supports the Legume Information System and related biodata websites
Apache License 2.0
2 stars 3 forks source link

Should array fields be returned as empty rather than null? #128

Closed sammyjava closed 9 months ago

sammyjava commented 9 months ago

I've hit an example of an array field (SOTerm.parents) being empty, which raises a question.

Right now my API method is returning null rather than an empty array. Which is fine with me, but I think we've been specifying non-null arrays in all of the types, whereas I've changed that to allow null for the array (but no null members) to prevent an error message. Should I modify the code to return an empty array rather than null, and do so in all cases of arrays? (I'm not sure why this is returning null rather than an empty array, TBH, but I'm sure I can figure that out if I need to).

image

sammyjava commented 9 months ago

I think the answer is "yes" but just checking that empty rather than null arrays is a design requirement.

alancleary commented 9 months ago

Yeah, I think empty arrays make more sense than null. Thanks for asking!