[网络错误]:错误:使用Apollo链接状态将结果写入存储以供查询时出错

[网络错误]:错误:使用Apollo链接状态将结果写入存储以供查询时出错,apollo,react-apollo,apollo-client,Apollo,React Apollo,Apollo Client,我正在使用Apollo链接状态为我的应用程序创建和更新存储。但是,我在执行变异时遇到以下错误: [Network error]: Error: Error writing result to store for query: query getLocation { location @client { coords __typename } } Cannot read property 'location' of undefined 我的默认存储如下所示: cons

我正在使用Apollo链接状态为我的应用程序创建和更新存储。但是,我在执行变异时遇到以下错误:

[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
    }
  }
`;
我在我的变体中使用的查询如下所示:

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

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

我看不出查询有什么问题。

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

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