gqless icon indicating copy to clipboard operation
gqless copied to clipboard

Improve documentation around updating with mutation data

Open outerlook opened this issue 3 years ago • 2 comments

Hi!

I would like to contribute writing some guides on docs for some operations around mutating data with mutation responses.

The topics I first though of are:

  • Updating data once a request is complete (append data, remove data, edit data)
    • with refetch
    • with setCache
    • with assignSelections
  • optimisticResponse

But I still didn't get how to do it all. Then I'll continue to understand this better while I rebuild my app to use svelte + gqless.

In meantime, do you have any other suggestion of topics I could improve on the docs around recipes we see on other graphql clients?

Are there any known limitations I don't know yet but you do?

Great current docs anyway, but I know it is an extensive work. :)

References

Apollo mutations Apollo optimistic update Relay mutations Urql cache mutations

outerlook avatar Jun 11 '21 14:06 outerlook

Hi, @outerlook, I guess you've gone through the source code and found out how the API should behave and want to share it with the rest of the world? I agree that docs are nice, and they could definitely use some work to make them more easily consumable.

I'm in a situation where I am creating an item in a list and I want to update the said list. The docs suggest doing this via the refetchQueries, however, I'd prefer to simply update the cached query with the newly created item, and since I'm also returning the newly created item as a response, this would be my preferred approach.

I guess setCache should help achieve this, but it is not clear to me how to use it.

Do you have any hints for me?

In regards to how to contribute to the documentation, have you had a chance to see this page https://gqless.com/contributing?

nemonemi avatar Jun 25 '21 20:06 nemonemi

Sure! Right now I'm migrating an entire codebase from react to svelte, and after that I would like to contribute with something around svelte bindings or something about docs.

Right now, my lastest solution was to build sort of a autoRefetchObjectQueries(typename, id) that refetches all queries on currently mounted components around an object identifier (type + id).

Then when I mutate some list, I refetch its parent queries. That is less performant than to surgically add an edge to a list, indeed. But right now I'm not running on any performance issue and it is really easy and manageable.

I can share my code for it later if you are interested on this.

If you are using react with gqless, I don't know for sure how you could access the currently mounted queries, because I only explored the core api and some hook. But it is not hard to follow the gqless useQuery code and try to figure out how to extend it.

Again, if this is some feature the library would like to offer, I would contribute as well.

outerlook avatar Jun 26 '21 01:06 outerlook