【问题标题】:apollo-link-state cache.writedata results in Missing field warningapollo-link-state cache.writedata 导致缺少字段警告
【发布时间】:2018-06-08 21:34:01
【问题描述】:

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

writeToStore.js:111 {} 中缺少字段 updateLocale

这是我的状态链接:

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

我错过了什么?

【问题讨论】:

    标签: apollo react-apollo


    【解决方案1】:

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

    【讨论】:

      【解决方案2】:

      我得到了同样的警告,并通过从变异方法返回数据来解决它。

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

      【讨论】:

        猜你喜欢
        • 2018-06-19
        • 1970-01-01
        • 2022-07-29
        • 1970-01-01
        • 1970-01-01
        • 2019-05-13
        • 1970-01-01
        • 2020-11-19
        • 2020-05-05
        相关资源
        最近更新 更多