Apollo returning null consistently
— Code, Typescript, Cache, Apollo — 1 min read
The problem
This is what your API returns
{ "data": { "items": [ { "id": null, "name": "Item 1" }, { "id": null, "name": "Item 2" }, { "id": null, "name": "Item 3" } ] }}
What is actually returned ⚠️
If you call the useQuery
that is provided in apollo ( version: "apollo-client": "2.6.10"
), this is what you get in the response.
{ "data": { "items": [ { "id": null, "name": "Item 1" }, { "id": null, "name": "Item 1" <--- should be Item 2 }, { "id": null, "name": "Item 1" <--- should be Item 3 } ] }}
Here's a StackOverflow post that also talks about this problem