plugin-graphql icon indicating copy to clipboard operation
plugin-graphql copied to clipboard

Optimistic UI

Open phortx opened this issue 6 years ago • 1 comments

The Apollo-Client supports Optimistic UI. It would be nice when this plugin would support that too.

We have to think about what this means and how this support could look like.

phortx avatar Jun 07 '18 14:06 phortx

I found myself wanting this today. Basically I want to insert a record, then do a API call, and on success update that record, or delete it on API error. The way Apollo does it sucks IMHO, it's so verbose. Would love VuexORM to make it more "Vue" like.

Perhaps something like this:

let optimistic = User.create({
  data: { id: 1, name: 'John Doe ' }
})

// Update API
this.$apollo.doSomething()
.then((result)=>{
     optimistic.success(result) // updates record with any extra server data
})
.error(()=>{
     optimistic.fail() // deletes record, rolls back an update etc.
})

That pattern is basically what I do using create() then update() then delete() methods and tracking the record ID, so not sure if this is any better than that approach. Maybe just having a suggested approach in the docs would be enough?

drewbaker avatar Jul 30 '20 09:07 drewbaker