【问题标题】:[Network error]: Error: Error writing result to store for query Using Apollo Link State[网络错误]:错误:使用 Apollo Link State 将结果写入存储以进行查询时出错
【发布时间】:2018-10-14 08:16:40
【问题描述】:

我正在使用 Apollo-link-state 为我的应用程序创建和更新商店。但是,执行突变时出现以下错误:

[Network error]: Error: Error writing result to store for query:
 query getLocation {
  location @client {
    coords
    __typename
  }
}

Cannot read property 'location' of undefined

我的默认商店如下所示:

const defaultState = {
   location: {
    __typename: 'Location',
    coords: [36, -87]
  },
};

export default defaultState;

我在突变中使用的查询如下所示:

export const GET_LOCATION = gql`
  query getLocation{
    location @client{
        coords
    }
  }
`;

我没有看到查询有什么问题。

【问题讨论】:

    标签: apollo react-apollo apollo-client


    【解决方案1】:

    您只是在 defaultState 中缺少默认位置对象的 id,就像这样尝试并工作:

    export default {
      location: {
        __typename: 'Location',
        id: 0,
        coords: [36, 23],
      },
    }
    

    【讨论】:

      猜你喜欢
      • 2017-11-08
      • 2019-07-27
      • 1970-01-01
      • 2020-03-01
      • 2018-09-18
      • 2019-10-18
      • 2018-09-26
      • 2017-11-20
      • 1970-01-01
      相关资源
      最近更新 更多