在apollo客户端2.0中更新缓存

loading...


0

我有以下查询:

const FETCH_CUSTOMERS = gql`
  query customers($cursor: Int!, $pageNumber: Int!) {
    customers(cursor: $cursor, pageNumber: $pageNumber)
      @connection(key: "customers", filter: ["pageNumber"]) {
      customers {
        customerID
        firstname
        lastname
        email
        phone
        CustomerPhoto {
          photo
        }
      }
      count
    }
  }
`;

执行Mutation时,我正在尝试更新缓存 . 执行操作 cache.writeQuery(...) 时会出现问题 .

<Mutation
      mutation={UPDATE_CUSTOMER}
      update={(
        cache,
        {
          data: {
            updateCustomer: { customer }
          }
        }
      ) => {
        const { page } = queryString.parse(search);
        const parsePageInt = parseInt(page, 10);
        const {
          customers: { customers }
        } = cache.readQuery({
          query: FETCH_CUSTOMERS,
          variables: { pageNumber: parsePageInt }
        });
         const updatedCustomersArray = customers.map(customerFromCache => {
           return customerFromCache.customerID === customer.customerID
             ? customer
             : customerFromCache;
         });
   cache.writeQuery({
       query: FETCH_CUSTOMERS,
      variables: { pageNumber: parsePageInt },
       data: { customers: { customers: updatedCustomersArray } }
     });

  />

缓存已更新但我收到以下错误:

在项目开始时,我添加了InMemoryCache对象属性 addTypename: false . 什么看起来是一个错误的决定,因为我之前决定使用带有接口和内联片段的查询,这需要架构中的 __typename 属性 .

这是apollo缓存中缓存查询的形状

有什么简单的方法可以解决它吗?

loading...

0回答

No Data

评论

暂时没有评论!