apollo-link-state cache.writedata 导致缺少字段警告

apollo-link-state cache.writedata results in Missing field warning

当我在我的客户端上调用突变时,我收到以下警告:

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);

我错过了什么?

我收到了同样的警告,并通过从变异方法返回数据解决了这个问题。

updateLocale: (root, { locale }, context) => {

  const data = {
    language: {
      __typename: 'Language',
      locale,
    }
  };
  context.cache.writeData({ data });
  return data;
};

目前,apollo-link-state 要求您return any 结果。也可以是 nullThis might be changed in the future.