未捕获的不变违规:存储错误

我正在尝试使用用 Go 编写的 graphql api 编写 HackerNews 克隆,并将 graph-gophers 包作为后端,以及使用 apollo graphql-client 作为前端的 Vuejs 应用程序。相关 Github Repos后端 Frontend。


我最近实现了订阅功能,它似乎确实有效,但是每当我对链接进行投票时,我都会在 javascript 控制台中收到一个令人讨厌的错误,其全文如下。


Observable.js?5234:65 Uncaught Invariant Violation: Store error: the application attempted to write an object with no provided id but the store already contains an id of Link:10 for this object. The selectionSet that was trying to be written is:

{"kind":"Field","name":{"kind":"Name","value":"link"},"arguments":[],"directives":[],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"votes"},"arguments":[],"directives":[],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"id"},"arguments":[],"directives":[]},{"kind":"Field","name":{"kind":"Name","value":"user"},"arguments":[],"directives":[],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"id"},"arguments":[],"directives":[]},{"kind":"Field","name":{"kind":"Name","value":"__typename"}}]}},{"kind":"Field","name":{"kind":"Name","value":"__typename"}}]}},{"kind":"Field","name":{"kind":"Name","value":"__typename"}}]}}

    at new InvariantError (webpack-internal:///./node_modules/ts-invariant/lib/invariant.esm.js:16:28)

    at invariant (webpack-internal:///./node_modules/ts-invariant/lib/invariant.esm.js:28:15)

    at StoreWriter.writeFieldToStore (webpack-internal:///./node_modules/apollo-cache-inmemory/lib/bundle.esm.js:680:166)

    at eval (webpack-internal:///./node_modules/apollo-cache-inmemory/lib/bundle.esm.js:576:27)


我已经进行了足够多的调试以确认我尝试添加到商店的任何内容都没有丢失任何 ID。我不确定我在这里缺少什么导致此错误。一切似乎都有效,但我想知道为什么这个错误不断被抛出。


小怪兽爱吃肉
浏览 162回答 1
1回答

长风秋雁

我最终弄清楚了这一点。错误的原因是在更新商店时发生 upvote 时,我一直专注于 graphql 模式中的投票订阅,而问题实际上是 upvote 突变。作为架构的一部分返回的链接缺少 id。
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Go