apollo-cache-invalidation icon indicating copy to clipboard operation
apollo-cache-invalidation copied to clipboard

Throws exception when clearing a cached result of `null`

Open dallonf opened this issue 8 years ago • 3 comments

When one of my patterns matches a path in the store that has a value of null, I get this error:

apollo.umd.js:1508 TypeError: Cannot convert undefined or null to object
    at Function.keys (<anonymous>)
    at isReference (webpack:///./~/apollo-cache-invalidation/lib/index.js?:42:17)
    at Object.findMatches (webpack:///./~/apollo-cache-invalidation/lib/index.js?:64:9)
    at Object.eval (webpack:///./~/traverse/index.js?:59:22)
    at walker (webpack:///./~/traverse/index.js?:190:22)
    at eval (webpack:///./~/traverse/index.js?:208:29)
    at Array.forEach (native)
    at forEach (webpack:///./~/traverse/index.js?:298:31)
    at walker (webpack:///./~/traverse/index.js?:203:13)
    at eval (webpack:///./~/traverse/index.js?:208:29)

Looks like the problem is that findMatches assumes that this.node is an object and not null.

dallonf avatar May 30 '17 16:05 dallonf

Could you work on a pull-request?

lucasconstantino avatar May 31 '17 21:05 lucasconstantino

Unfortunately I don't have a lot of time right now and I was able to find a workaround that was actually probably a better choice in my particular scenario (instead of invalidating that particular part of the cache, I called writeQuery to populate it since I had the data that should go there available) Sorry :(

dallonf avatar May 31 '17 21:05 dallonf

Thanks for pointing out the bug ;)

lucasconstantino avatar May 31 '17 22:05 lucasconstantino