I am considering using React Relay or the Apollo Client. I like the idea of GraphQL as a query language that can be executed against any API or data store.
However, I am surprised by the need to manually (and imperatively) update the store/cache after a simple mutation such as adding a todo item to a list. Here is the documentation for the updater/update functions:
http://facebook.github.io/relay/docs/en/mutations.html https://www.apollographql.com/docs/react/essentials/mutations.html
Why is a user-defined updater function required?
Specifically, why must I write an updater function to handle running these two GraphQL queries in sequence?
//Create todo item
mutation createTodo($input: TodoInput!) {
createTodo(input: $input) {
id
name
desc
}
}
mutationVariables = { input: { name: 'Shopping', desc: 'Get groceries' }};
//Select all todos
query {
todos {
id
name
desc
}
}
Why would the todos query not return the new todo item automatically? That is the POINT of a declarative query language IMO.