Why can everything be null? #161
-
The readme has this image example: And you can see how the data data is typed as: {
pokemons: ({ id: string | number } | null)[] | null;
} Why is not like this? {
pokemons: ({ id: string | number })[];
} When I do the query, I always get an array. On what occasion can null arrive? Or am I missing something? I ask because then the way to use it is: data?.pokemons?.map(pokemon => pokemon!.id) Instead of: data.pokemons.map(pokemon => pokemon.id) Is there any other workaround to have a better development experience? Thanks! |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
I mean, in GraphQL the server sais whether something can be nullable or not. Indicating something as nullable acts like a boundary for errors,... it can also be used on the client to indicate where partial data is allowed. I highly encourage you to read the spec to know more about this. Basically this isn't a question that can be answered from this library as it's a building block of GraphQL as a technology. Wrote a bit about it here https://stellate.co/blog/graphql-types-as-a-superpower and a reddit post https://www.reddit.com/r/graphql/s/0bESQWSZ8P Tldr: when a field errors for a given pokemon that would bubble up to the first non nullable boundary. If we ask for a list of pokemons and then for one pokemon but with more fields the nullability of those fields can instruct us to show partial data. |
Beta Was this translation helpful? Give feedback.
I mean, in GraphQL the server sais whether something can be nullable or not. Indicating something as nullable acts like a boundary for errors,... it can also be used on the client to indicate where partial data is allowed. I highly encourage you to read the spec to know more about this.
Basically this isn't a question that can be answered from this library as it's a building block of GraphQL as a technology.
Wrote a bit about it here https://stellate.co/blog/graphql-types-as-a-superpower and a reddit post https://www.reddit.com/r/graphql/s/0bESQWSZ8P
Tldr: when a field errors for a given pokemon that would bubble up to the first non nullable boundary. If we ask for a list of pokemons and …