Updating GraphQL cache when using Content Management API


We are using Apollo to query the DatoCMS GraphQL API and cache the results. This is working fine. I understand that the GraphQL API is read only, so no mutations. What is the recommended way to handle data management via the Content Management API and mutate the data in our Apollo cache. Should we be using Apollo Link to query the rest API? If so, do you have an example we can look at?

Hello @chad1 and welcome to Community! :slight_smile:

I don’t think you should use Apollo Link to query the REST API.

Have you considered regetting the schema after a changes? Using something like this: https://github.com/datocms/react-apollo-demo#setting-up-apollo-client maybe?

Hi @mat_jack1!

Thanks for the tip. You might want to update your Apollo example. Looks like IntrospectionFragmentMatcher does not exist in Apollo 3.0, should be using PossibleTypes now.

I guess the problem we are trying to solve is trying to make our app’s UI more optimistic. Ideally we will be updating the cache first as an operation is taking place. So if we update a record, the changes show in the UI immediately. In the past we have handled this using Apollo’s cache and useMutation hook, which does it for us. We love the DatoCMS GraphQL API, but are trying to figure out a strategy using your Content Management API. We are using the Real-Time api to keep the DB and cache in sync, though that still ultimately requires a fetch, and are wondering what your preferred strategy for cache management is using the Content Management API while keeping the UI optimistic. Should we be manually updating the cache when using that API?

Hey @chad1 unfortunately we don’t support your workflow now. Maybe you can implement something on your end using webhooks to trigger a cache update? Sorry not being able to help you more here :frowning: