apollo-link-state cache.writedata 导致缺少字段警告 [英] apollo-link-state cache.writedata results in Missing field warning
本文介绍了apollo-link-state cache.writedata 导致缺少字段警告的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
当我在我的客户端上调用一个mutation时,我收到以下警告:
When I call a mutation on my client I get the following warning:
writeToStore.js:111 {} 中缺少字段 updateLocale
writeToStore.js:111 Missing field updateLocale in {}
这是我的状态链接:
const stateLink = withClientState({
cache,
resolvers: {
Mutation: {
updateLocale: (root, { locale }, context) => {
context.cache.writeData({
data: {
language: {
__typename: 'Language',
locale,
},
},
});
},
},
},
defaults: {
language: {
__typename: 'Language',
locale: 'nl',
},
},
});
这是我的组件:
export default graphql(gql`
mutation updateLocale($locale: String) {
updateLocale(locale: $locale) @client
}
`, {
props: ({ mutate }) => ({
updateLocale: locale => mutate({
variables: { locale },
}),
}),
})(LanguagePicker);
我错过了什么?
推荐答案
我收到了同样的警告,并通过从mutation 方法返回数据来解决它.
I was getting the same warning and solved it by returning the data from the mutation method.
updateLocale: (root, { locale }, context) => {
const data = {
language: {
__typename: 'Language',
locale,
}
};
context.cache.writeData({ data });
return data;
};
这篇关于apollo-link-state cache.writedata 导致缺少字段警告的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文