morrys / wora

Write Once, Render Anywhere. typescript libraries: cache-persist, apollo-offline, relay-offline, offline-first, apollo-cache, relay-store, netinfo, detect-network
https://morrys.github.io/wora/docs/introduction
MIT License
174 stars 4 forks source link

Architecture documentation #2

Open wtrocki opened 5 years ago

wtrocki commented 5 years ago

Can you provide more info how you see offline functionalities being developed and how you see future of this library going forward? Any info will be useful

morrys commented 5 years ago

Soon I will create a roadmap within github to highlight the macro themes that will be addressed by the individual libraries.

The architecture and related documentation will be extended and integrated according to the needs of the community.

As for the apollo libraries, the features introduced extend the original ones without altering the behavior of the client when the network status is online.

wtrocki commented 5 years ago

Yes. I like the idea. Any reason why users will need to use custom replication protocol in execute? I see that you can change this to use the same graphql mutations and url. I meant there could be some motivation for that use case, but overal framework will be much simpler if offline data will be replicated seamlessly they same way.

Are you familiar wityh the concept of the Apollo-link-queue? https://github.com/helfer/apollo-link-queue/issues/3

It could seriously simplify your library.

wtrocki commented 5 years ago

Soon I will create a roadmap within github to highlight the macro themes that will be addressed by the individual libraries.

This sounds amazing!

morrys commented 5 years ago

are you talking about link: httpLinkOffline in https://github.com/morrys/wora/tree/master/packages/apollo-offline#apollo-client-with-offline-options ?

wtrocki commented 5 years ago

Yes.

morrys commented 5 years ago

it is not mandatory to enter this option, by default the same link is used to execute mutations online.

I gave this opportunity just to give the possibility to insert custom logics for offline mutations. For example, different retry links, different error handling, payload check or all those needs that may arise based on the use case.

morrys commented 5 years ago

I could tell you a thousand possible solutions of use but without a requirement and / or a problem it is useless.

wtrocki commented 5 years ago

That is a really interesting approach. Is this global handler then or we can apply this with UI binding? Can I use Apollo component in react with this?

How enqueueing happens? When I hit client.mutate() and I'm offline do I get any response in promise or error or this will be blocked until the change is replicated to server?

I think I'm getting the entire framework slowly and this looks impressive.

wtrocki commented 5 years ago

Checked example: https://github.com/morrys/offline-examples/blob/master/apollo/todo/client/src/components/TodoOffline.js

It looks like there will be couple migration steps require to use it starting from vanilla Apollo application. It will be easy to avoid that IMHO assuming that offline mutations are not blocking.

morrys commented 5 years ago

Queuing occurs asynchronously and responds to the UI with the optimistic response. It does not keep the ui locked and absolutely does not wait for any response from the server.

Execution is performed in the background once the connection becomes available (and it is also possible to manage it manually).

morrys commented 5 years ago

https://github.com/morrys/wora/blob/master/packages/apollo-offline/src/ApolloStoreOffline.ts#L155

morrys commented 5 years ago

Checked example: https://github.com/morrys/offline-examples/blob/master/apollo/todo/client/src/components/TodoOffline.js

this react component is the one I talk about in this comment: https://github.com/morrys/wora/issues/3#issuecomment-512357653

morrys commented 5 years ago

to use the library this class is enough:

https://github.com/morrys/offline-examples/blob/master/apollo/todo/client/src/apollo/index.js

and this:

https://github.com/morrys/offline-examples/blob/master/apollo/todo/client/src/app.js#L65-L68

as documented here: https://github.com/morrys/wora/tree/master/packages/apollo-offline#apollo-client