Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Explicit cache update not needed when valid optimisticResponse defined in react apollo hooks? #193

Closed
martinpengellyphillips opened this issue May 2, 2020 · 1 comment

Comments

@martinpengellyphillips
Copy link

martinpengellyphillips commented May 2, 2020

Shouldn't the react-apollo-hooks/tutorial-site/content/optimistic-update-mutations/2-mutation-cache.md example just define a valid optimisticResponse and skip defining the cache update as that will be handled automatically by Apollo for a simple update?

E.g.

  const toggleTodo = () => {
    toggleTodoMutation({
      variables: { id: todo.id, isCompleted: !todo.is_completed },
      optimisticResponse: {
        update_todos: {
          __typename: 'todos_mutation_response',
          affected_rows: 1,
          returning: [
            {
              __typename: 'todos',
              id: todo.id,
              is_completed: !todo.is_completed
            }
          ]
        }
      },
    })
  }

Note that I am new to Hasura, Apollo and GraphQL so might be wrong about this 😄

@martinpengellyphillips martinpengellyphillips changed the title Explicit cache update not needed when valid optimisticResponse defined in react apollo hooks? Explicit cache update not needed when valid optimisticResponse defined in react apollo hooks? May 2, 2020
@praveenweb
Copy link
Member

@martinpengellyphillips - Hi, you are right. Defining an optimistic response should do just fine. The tutorial goes over different ways of doing things to cover all sorts of use cases in this small todo app 😄 (Like optimistic UI, manual cache updates, using client.query vs useQuery hook) and hence the usage.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants