# OptimisticUpdate not trigering watch update

**URL:** <https://community.apollographql.com/t/optimisticupdate-not-trigering-watch-update/6952>\
**Category:** Client SDKs\
**Tags:** client, mobile, kotlin\
**Created:** [November 16, 2023, 7:18pm UTC](https://community.apollographql.com/t/optimisticupdate-not-trigering-watch-update/6952 "2023-11-16T19:18:29Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Marco\_Pierucci](https://sea1.discourse-cdn.com/flex019/user_avatar/community.apollographql.com/marco_pierucci/32/4743_2.png) [@Marco\_Pierucci](https://community.apollographql.com/u/Marco_Pierucci)\
**Post date:** [November 16, 2023, 7:18pm UTC](https://community.apollographql.com/t/optimisticupdate-not-trigering-watch-update/6952/1 "2023-11-16T19:18:29Z")

</div>

I’ve set up some initial cache config on out project ( Usingo apollo 3.4.0) After inpsecting the data base I can see the Cache entries are generated correctly with the corresponding Ids.  
I have a watch function that looks like:

```auto
    fun workOrder(id: String): Flow<Pair<WorkOrderInfo, List<FetchWorkOrderQuery.ValidFieldsetOption>>> {
        return apolloClient.query(FetchWorkOrderQuery(id = id))
            .fetchPolicy(FetchPolicy.CacheFirst)
            .watch()
            .map {
                //TODO check error handling
                val data = it.dataAssertNoErrors
                val workOrderInfo = data.workOrder?.workOrderInfo
                    ?: throw NullPointerException("Job $id Not found")
                workOrderInfo to (data.validFieldsetOptions ?: emptyList())
            }
    }

```

and a mutation that updates a component like

```auto

        apolloClient.mutation(UpdateTaskComponentsMutation(input = newComponents))
            .optimisticUpdates(
                UpdateTaskComponentsMutation.Data(
                    UpdateTaskComponentsMutation.UpdateTaskComponents(
                        listOf(
                            UpdateTaskComponentsMutation.Component(
                                __typename = newComponent.componentInfo.__ typename,
                                componentInfo = newComponent.componentInfo,
                                id = newComponent.componentInfo.id
                            )
                        )
                    )
                )
            )
            .execute()

```

This code not only does not trigger the watch to refeth but as far as I can see not even writes the catche ( exiting the screen and re enteris still shows the initial cache value).

I also tried the following store operation:

```auto
     apolloClient.apolloStore.writeOperation(
                operation = UpdateTaskComponentsMutation(
                    input = newComponents
                ),
                operationData = UpdateTaskComponentsMutation.Data(
                    UpdateTaskComponentsMutation.UpdateTaskComponents(
                        listOf(
                            UpdateTaskComponentsMutation.Component(
                                __typename = newComponent.componentInfo.__ typename,
                                componentInfo = newComponent.componentInfo,
                                id = newComponent.componentInfo.id
                            )
                        )
                    )
                )
            )

```

This seems to be writting into the cache ( If you exit and re enter the screen you see the new value, also there are entries in the cache as well for the update mutation) but it still wont make the watcher to emit the new written value.  
Am I missing something?

---

<div class="post-metadata">

**Author:** ![Justin\_Gonzalez](https://sea1.discourse-cdn.com/flex019/user_avatar/community.apollographql.com/justin_gonzalez/32/5359_2.png) [@Justin\_Gonzalez](https://community.apollographql.com/u/Justin_Gonzalez)\
**Post date:** [February 6, 2025, 8:47pm UTC](https://community.apollographql.com/t/optimisticupdate-not-trigering-watch-update/6952/2 "2025-02-06T20:47:57Z")

</div>

Archived on February 6, 2025, 8:47pm UTC


