1

我只是在测试一个简单的案例,我可以在其中添加猫并显示猫的详细信息。但我收到了这个错误 bundle.esm.js:805 Invariant Violation: Can't find field color on object { "id": "5cf74600ed38a91e472e0e20", "name": "Rose", "breed": "Italian", "__typename": "Cat" }

当我添加新猫后尝试更新缓存时

this.apollo.mutate<CreateCatMutationResponse>({ mutation: CREATE_CAT_MUTATION, variables: { name: this.name, breed: this.breed, color: this.color }, // awaitRefetchQueries: false, update: (store, {data: {createCat}}) => { // Read the data from our cache for this query. const data: any = store.readQuery({query: cats, variables: {id: createCat.id}});

    // Add our comment from the mutation to the end.
    if (data) {
      data.cats.push(createCat);
    }
    // Write our data back to the cache.
    store.writeQuery({query: cats, data});
  },
}`

因为在我试图添加一只新猫的页面中,它只显示了 2 个属性,即名称和品种,而不是颜色:

this.allCat = this.apollo.watchQuery<Query>({ query: gql 查询猫{猫{id名称品种}} , fetchPolicy: 'cache-and-network' }) .valueChanges .pipe( map(result => result.data.cats) ); }

任何想法如何在不使用重新获取查询的情况下摆脱这个问题?

4

0 回答 0