1

我的 readQuery 正在返回一个field not found错误,即使该字段似乎存在于缓存中。

询问

const GETIMSFROMCACHE_QUERY = gql`
query getIMsFromCache($fromID: String!){
  instant_message(fromID:$fromID){
    id,
    fromID,
    toID,
    msgText
  }
}  `;

缓存解析器

client.cache.cacheResolvers = {
    Query: {
        instant_message: (_, args) => toIdValue(client.dataIdFromObject({
            __typename: 'instant_message',
            id: args.id
        })),
    },
};

READQUERY CALL,更新中

let instant_message = cache.readQuery({ query: GETIMSFROMCACHE_QUERY, variables: {"fromID": fromID} });

错误

Error: Can't find field instant_message({"fromID":"ayqNLcA7c6r8vip3i"}) on object (ROOT_QUERY) {
  "getMyUserData({\"id\":\"ayqNLcA7c6r8vip3i\"})": [
    {
      "type": "id",
      "generated": false,
      "id": "MyUserData:ayqNLcA7c6r8vip3i",
      "typename": "MyUserData"
    }
  ],
  "getMyUserData({\"id\":\"9W95z8A7Y6i34buk7\"})": [
    {
      "type": "id",
      "generated": false,
      "id": "MyUserData:9W95z8A7Y6i34buk7",
      "typename": "MyUserData"
    }
  ],
  "Appts({\"originatingUserID\":\"ayqNLcA7c6r8vip3i\"})": [],
  "instant_message({\"fromID\":\"ayqNLcA7c6r8vip3i\",\"toID\":\"9W95z8A7Y6i34buk7\"})": [
    {
      "type": "id",
      "generated": false,
      "id": "instant_message:126",
      "typename": "instant_message"
    },
    {
      "type": "id",
      "generated": false,
      "id": "instant_message:127",
      "typename": "instant_message"
    },
    {
      "type": "id",
      "generated": false,
      "id": "instant_message:128",
      "typename": "instant_message"
    }
  ]
}.

查看错误消息,ROOT_QUERY 对象上似乎存在一个instant_message具有目标用户 ID 的对象,但我收到此错误。

我该如何纠正?

提前感谢所有人提供的任何信息。

4

1 回答 1

0

解决了!这很棘手,因为原始查询的常规解析器会带回来自两个用户中的任何一个的任何 IM。fromID解析器返回 from和 to的任何 Instant_messages toID反之亦然

所以我想我需要某种缓存解析器来在查询缓存时重复这个。

最终我意识到缓存并不关心解析器中发生了什么——它会将 Instant_message 对象存储为 fromfromID和 to toID,而不管解析器中发生了什么。

一旦我意识到这一点,我就删除了特殊的缓存解析器查询,只使用了最初检索到 Instant_messages 的原始查询,并首先使用了相同的查询变量,并且它起作用了。:)

于 2018-06-10T02:05:40.390 回答