I'm using Apollo Client and am learning Typescript. I have a Mutation component with this update prop:
(cache, { data: { createTask } }) => {
const allTasks = cache.readQuery({ query: ALL_TASKS }).allTasks;
}
I get two compilation errors:
Object is possibly 'null'.
Property 'allTasks' does not exist on type '{}'.
I understand the general idea. readQuery might return null (which is it self confusing because the docs lead me to believe that an error is thrown when no results are found (https://www.apollographql.com/docs/react/advanced/caching.html#readquery).
How can I get the compiler to let me read the property allTasks from the result of readQuery?
Also, FYI I tried running console.log(cache.readQuery({ query: ALL_TASKS })) and confirmed that there is indeed valid data there with a property called.