Anyone using GraphQL? Will it work well with Retro...
# android
s
Anyone using GraphQL? Will it work well with Retrofit? Whats the advantages/disadvantages?
v
try #graphql
✔️ 2
x
I'm currently using GraphQL with the android Apollo library. What's nice is that you can declare your schema and specs of each requests and it generates the appropriate builders. No need to use Retrofit at all.
One of the advantage is that you define the exact data you want to receive for each request. Say you ony want the id field for each user you can. Or if you want the full user, you can too.
Biggest disadvantage, IMHO, is that with Apollo, you have a distinct model class for each request, meaning that you can't share any conversion or treatment code. (there might be a trick to that but haven't found it yet)
w
@Xavier F. Gouchet While you will always have separate model classes for requests, you can wrap common structures in Fragments. They’ll have single model generated and may simplify things for you
You can also have an entire response a fragment, but you will still have a top-level
Data
class specific for that request. But you would be able to immediately access fragment from it
👍 1
s
fragment is not the Fragment we know in android I suppose? Apollo can't reuse data classes, lets say, one where you don't use all the fields? I also found Anitrend retrofit converter for GraphQL,. havn't tested anythig yet but it's 100% kotlin and I suppose we can use Retrofit normally.
a
Use Apollo as GraphQL client - it supports Kotlin models generation as well.
👍 1
v
@Xavier F. Gouchet You said "One of the advantage is that you define the exact data you want to receive for each request" How would you then store data in a relational db like Room? What if your query doesn't have an id for example?
x
Well that's up to you I guess. That's the power of GraphQL : you ask for what you need. If you need the id in all requests, you can ask for it. If you need to store data in Room (or any other storage), having the id is usually a requirement, but then you can generate a local id based on some identifying info in the model
s
It's a good idea to get only what is needed, save data and loading time.
Apollo as the same features as Retrofit?