1
votes

I have a screen where I run a query and render some items based on the results:

query getMyFavoritePlaces($myID: String) {
  favorite_place(where: { user_id: { _eq: $myID } }) {
    id
    location
    label
    user{
      id
    }
    user_id
  }
}
const { data, error } = useGetMyFavoritePlacesQuery({ variables: { myID: profile.id }});
{
    data && (
    <FlatList
      data={data.favorite_place}
      renderItem={({ item }) => <FavoriteLocationEntry place={item} />}
      keyExtractor={(item) => item.id.toString()} />
    )
}

When I run this mutation by clicking on any of the items from the flatlets:

mutation RemoveFavoriteLocation($id: Int!) {
  delete_favorite_place_by_pk(id: $id) {
    id
    location
    label
    user{
      favorite_places {
        id
         location
          label
      }
    }
    user_id
  }
}

The object gets deleted successfully and the UI is also updated. However, I get a warning that

Cache data may be lost when replacing the favourite_place field of a Query object. To address this problem define a custom merge function for the Query.favorite_place field, so InMemoryCache can safely merge these objects: { ... } enter image description here

The values shown here are the ids. I am already returning ids in both, the query and mutation. How can I fix it then?

It might not be possible to run the favourite_place query itself within the mutation.

1

1 Answers

0
votes

Your mutation needs to include an id field for the user or it may mistakenly delete a favourite_place field for a different user:

mutation RemoveFavoriteLocation($id: Int!) {
  delete_favorite_place_by_pk(id: $id) {
    id
    location
    label
    user{
      **id**
      favorite_places {
        id
        location
        label
      }
    }
    user_id
  }
}

P.s please don't include the asterisks, just there to bring focus to the missing property.