Modifying content fragments in Java code sometimes updates the GraphQL indexes and sometimes doesn't
The team I'm on is running into a strange issue when editing content fragments in Java. A common pattern we use based on years of working with AEM is to adapt a resource as a ModifiableValueMap in Java code and then edit one of the values of that ModifiableValueMap, commit the resourceResolver, thus saving the change. When we perform this action against content fragments the saved property has always been searchable in GraphQL, so we assumed this pattern was fine.
Recently we encountered a bug when performing content fragments in an implementation of the replication PreProcessor. Basically as a content fragment was published we used the PreProcessor hook to add a new field and then continue with publishing the fragment. The problem is that if we use the same ModifiableValueMap to perform the update, this new value isn't indexed. I understand that we should be using the Content Fragment API. It was being used initially and the value was being indexed. We'll go back to using the Content Fragment API, especially after encouragement from this presentation. https://adapt.to/2023/schedule/optimising-graphql-delivery-in-aem
What I'm wondering is this. Why does the data get indexed properly when using the ModifiableValueMap (essentially using the Sling API) and in other contexts the property isn't indexed? I'm wondering if anyone else has encountered this and can explain what the difference might be so that we can make sure to update our Java code accordingly.
