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

Mvvm implementation with coroutines #2521

Open
Tracked by #6147
pratthama-appdesk opened this issue Aug 11, 2020 · 12 comments
Open
Tracked by #6147

Mvvm implementation with coroutines #2521

pratthama-appdesk opened this issue Aug 11, 2020 · 12 comments

Comments

@pratthama-appdesk
Copy link

Hi, is there any guide on how to implement apollo with mvvm architecture using coroutines?

@martinbonnin
Copy link
Contributor

Hi! You can take a look at this repo for an exemple of using Apollo Android with ViewModels: https://github.com/BoD/apollo-graphql-android-sample

@pratthama-appdesk
Copy link
Author

Hi! You can take a look at this repo for an exemple of using Apollo Android with ViewModels: https://github.com/BoD/apollo-graphql-android-sample

I don't think that's what I am looking for.
There are a lot of tutorials to implement Rest api with Retrofit using Coroutines, Livedata and MVVM architecture with repository pattern but no tutorials for Apollo. Is there something similar for apollo?

@martinbonnin
Copy link
Contributor

I'm not aware of anything like this unfortunately. Apollo is a way access your API like Retrofit so swapping out the retrofit Service with an ApolloClient should be close enough to the end result.
Can you share a good tutorial for retrofit and I'll look into how that would work with Apollo?

@pratthama-appdesk
Copy link
Author

I'm not aware of anything like this unfortunately. Apollo is a way access your API like Retrofit so swapping out the retrofit Service with an ApolloClient should be close enough to the end result.
Can you share a good tutorial for retrofit and I'll look into how that would work with Apollo?

Hi, here is a very good and perfect implementation of everything i talked about
https://blog.mindorks.com/using-retrofit-with-kotlin-coroutines-in-android
Thanks for your help.

@pratthama-appdesk
Copy link
Author

Any update on this?

@sav007
Copy link
Contributor

sav007 commented Aug 23, 2020

Apollo provides implementation for the networking layer for GraphQL API the same way as Retrofit provides implementation for networking layer for REST API. So technically if you replace anything related to the Retrofit with Apollo in the article you provided as a sample, you will get what you are looking for.

@pratthama-appdesk
Copy link
Author

Apollo provides implementation for the networking layer for GraphQL API the same way as Retrofit provides implementation for networking layer for REST API. So technically if you replace anything related to the Retrofit with Apollo in the article you provided as a sample, you will get what you are looking for.

The implementation for retrofit and apollo is really different and I don't think you can just replace Retrofit stuff with Apollo with exact same structure
If you guys can provide an example that would be really helpful.
The major concern with respect to the article is the Interface that has been set up since Apollo doesn't use annotations for end points and queries how to set that up?
Thanks

@pratthama-appdesk
Copy link
Author

Any help?

@hoodedice
Copy link

hoodedice commented Sep 6, 2020

Note: I'm new to android development.

I made a data access layer for apollo in an android app based on work done by my colleague with setting up a Room database (we're replacing the room implementation with apollo), as well as the code samples hosted here: https://github.com/apollographql/apollo-android/tree/master/samples/kotlin-sample

the repository I linked has been a great resource, and they do have code examples for coroutines as well (I went with rxJava).

As for your specific question about interfaces, I'm guessing they are similar to android's Room db interfaces -- I replaced those with abstract classes for every model we're tracking. I needed to use abstract classes because I "plug in" the correct datasource in the viewModel on runtime, extending them from a base abstract class.

I hope that these are enough pointers to get you started.

@jorgenfaunaapp
Copy link

Hi, I also would love the official apollo android guide to follow googles recommended design patterns. Is there any reason as to why the apollo guide is not using LiveData?

@martinbonnin
Copy link
Contributor

Hi @jorgenfaunaapp sorry for the hugeee delay! There's no specific reason not to include more documentation and guides. The main one is that all this takes a lot of time and it's a tradeoff between writing new features, maintaining the library vs writing documentation. There are a few different architectures out there and every team has its preferences. If you add other dimensions into the mix like compose vs views, RxJava vs Coroutines, etc... covering everything and keeping everything up to date is a huge task.

That being said, documentation is hugely important and we'll make a pass at the tutorial and samples for the upcoming 3.0 release. Certainly updating to new architectural patterns and jetpack compose along the way

We're also happy to link any community samples. If you have a repo with your preferred architecture or a blog post that helped you, feel free to send it so we can review it and include it in the docs.

@rishidholkheria
Copy link

Hi, Any update on the docs? @martinbonnin
PS: Am using v3 of apollo

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

No branches or pull requests

6 participants