A nicer way to get current Apollo GraphQL cache variables for writeQuery/readQuery?

Viewed 40

I’m currently using cache.watches.values().next().value to get the current query variables for cache interactions, e.g:

export const useUpdateProject = () => {
  const [updateProjectMutation] = useMutation(UPDATE_PROJECT, {
    update: (cache, { data: { updateProject } }) => {
      const { variables } = cache.watches.values().next().value
      cache.writeQuery({
        query: GET_PROJECT,
        variables,
        data: { project: updateProject }
      })
    }
  })
  return updateProjectMutation
}

…but maybe there’s a neater way to do this?

0 Answers
Related