问题描述
当我在我的客户端上调用突变时,我会收到以下警告:
writetostore.js:111丢失的字段Updatelocale在{}
这是我的statelink:
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);
我错过了什么?
推荐答案
i通过从突变方法返回数据来获得相同的警告并解决.
updateLocale: (root, { locale }, context) => { const data = { language: { __typename: 'Language', locale, } }; context.cache.writeData({ data }); return data; };
其他推荐答案
问题描述
When I call a mutation on my client I get the following warning:
writeToStore.js:111 Missing field updateLocale in {}
This is my stateLink:
const stateLink = withClientState({ cache, resolvers: { Mutation: { updateLocale: (root, { locale }, context) => { context.cache.writeData({ data: { language: { __typename: 'Language', locale, }, }, }); }, }, }, defaults: { language: { __typename: 'Language', locale: 'nl', }, }, });
And this is my component:
export default graphql(gql` mutation updateLocale($locale: String) { updateLocale(locale: $locale) @client } `, { props: ({ mutate }) => ({ updateLocale: locale => mutate({ variables: { locale }, }), }), })(LanguagePicker);
What am I missing?
推荐答案
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; };
其他推荐答案
At the moment, apollo-link-state requires you to return any result. It can be null too. This might be changed in the future.