1

I am just testing a simple case where I can add cats and show cat details. But I am getting this error bundle.esm.js:805 Invariant Violation: Can't find field color on object { "id": "5cf74600ed38a91e472e0e20", "name": "Rose", "breed": "Italian", "__typename": "Cat" }

when I try to update cache after adding a new 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});
  },
}`

Its becuse in the page that I am trying to add a new cat shows only 2 properties ie name and breed and not color :

this.allCat = this.apollo.watchQuery<Query>({ query: gql query cats { cats { id name breed } } , fetchPolicy: 'cache-and-network' }) .valueChanges .pipe( map(result => result.data.cats) ); }

Any Idea how can I get rid of this issue without using refetch queries?

vicky shrestha
  • 147
  • 1
  • 11

0 Answers0