vue-apollo是否有可能从游乐场返回不同的结果?

问题描述 投票:0回答:1

我有一个名为myAccounts的GraphQL查询,该查询返回一个帐户数组。当我去游乐场并致电查询时:

{
    accounts {
        email
    }
}

我得到这个结果:

"data": {
    "accounts": [
        {
            "email": "[email protected]",
        },
        {
            "email": "[email protected]",
        }
    ]
}

但是,当我在组件中时,vue-apollo返回数组中的两项,但是似乎用第一项覆盖了第二项。这是查询(在MyAccounts.gql中):

query myAccounts {
    accounts: myAccounts {
        email
    }
}

这是组件中的Apollo查询:

import MY_ACCOUNTS_QUERY from '~/apollo/queries/MyAccounts'
...
apollo: {
    accounts: {
        query: MY_ACCOUNTS_QUERY,
        result(data) {
            console.log(JSON.stringify(data))
        }
    }
}

这是vue-apollo通过result注销的内容:

{
   "data":{
      "accounts":[
         {
            "email":"[email protected]",
            "__typename":"Account"
         },
         {
            "email":"[email protected]",
            "__typename":"Account"
         }
      ]
   },
   "loading":false,
   "networkStatus":7,
   "stale":false
}

预期行为我希望在Playground中返回的数据与vue-apollo正在获取的数据相同。

版本提示:2.6.10vue-apollo:@nuxtjs/apollo: 4.0.0-rc18

其他上下文我以为result钩子将是调试的最佳方法,但任何其他建议都将受到欢迎。我以为这是我们代码中的错误,但是我无法弄清楚是什么导致重复(和不匹配)。

graphql apollo-client nuxt vue-apollo graphql-playground
1个回答
0
投票

从纪尧姆·周(https://github.com/Akryum):

这是因为Apollo客户端缓存无法计算其他ID这两个项目,因此您最终得到Account:undefined(或类似名称)对彼此而言。打开Apollo devtools,然后看一下myAccounts键缓存。

了解更多:https://www.apollographql.com/docs/react/caching/cache-configuration/

© www.soinside.com 2019 - 2024. All rights reserved.