How to use GraphQL with Retrofit on Android?

I am new to GraphQL, but now I am using Retrofit and it is easy to use and fast. GraphQL is very different from the rest of apis in terms of how you pass the data. There really aren't many tutorials on using GraphQL with Android, I could find this video ( https://www.youtube.com/watch?v=P0uJHI7GjIc&t=1s ), but there is no real code.

In my current code for callbacks, I have an endpoint that I set like this:

final RestAdapter restAdapter = new RestAdapter.Builder() .setEndpoint(endPoint) .build(); T service = restAdapter.create(clazz); 

Then I call the recreation service as follows:

 @GET("/users/{login}") Observable<Github> getUser(@Path("login") String login); 

Now with GraphQL you only have the base URL and there is no path to the service. In addition, if you are querying as userId = 1, then you need to send the Post parameters with the body:

 operationName: arbitrary name , query: "{users(userid:$userId){username}}, variables: "{"userId":1}" 

I'm just not sure how this translates to "Retrofit"

+6
source share
3 answers

Building queries and analyzing responses for GraphQL is not easy. If you use this on pet projects, I recommend starting learning Apollo. This client is under serious development, but you can already watch and play with it.

https://github.com/apollographql/apollo-android

So far I have enjoyed working with Apollo, and their roadmap has some nice features: RxJava integration, upgrades, subscription and AutoValue support.

+7
source

You cannot use the modification with GraphQL, because the modification is built for REST, you must use https://github.com/apollographql/apollo-android

it is specially assembly for graphQL

You should check this https://android.jlelse.eu/hello-apollo-writing-your-first-android-app-with-graphql-d8edabb35a2

0
source

Check out this link, it explains how to make POST and GET requests via HTTP. I tried this and this is what I got. Image of my request from graphql endpoint

https://graphql.imtqy.com/learn/serving-over-http/

-3
source

Source: https://habr.com/ru/post/1260545/


All Articles