Hello Team,
Its regarding Synchronous and Asynchronous Responses for Apollo Client in Java. While i was exploring the Kotlin Client initially but as per the suggestions on the forum Android V2 version is more close for Java Functionality.
As a part of evaluation and at-times users require operations to be blocking and hence, i need to know if there is a way to get the responses in Synchronous way,
If yes please do let me know how do we get to work with making the Operations Synchronous in Java.
Not sure if you are working on an Android project, but if so, blocking the main thread or executing any sort of disk or network operation on it is a bad practice which is why an asynchronous API would make more sense here.
If you really need to, you could make your own wrapper to transform the callback-based API into a blocking one, for instance by using a CountDownLatch.
Hi @Benoit_Lubek , No i am not working on an Android Project, I have an internal application in Java which will be using it to query GraphQL Server. The other perspective is i think using Kotlin Client its possible in V3, was thinking if there is a way to leverage the functionality or if it got introduced in V3 only.
@Benoit_Lubek@mbonnin : Another quick query i have is that the Asynchronous operations in GraphQL Java Client is supported only by callbacks or do we have the support/future plans for supporting Asynchronous operations using Promises as well?
Hi! For now the only supported API is coroutines, and adapters for Rx. There are also ways to bridge coroutines with Java’s Future for instance (see here), so you may want to experiment with it.
We also intend to have a better Java interop in the future, and you can monitor this ticket to be informed about it and give feedback.
@mbonnin : I have another query related to the responses from the Query Execution, In the examples at https://graphql.org/learn/schema/ generally the responses of a GraphQL Query Operation is a json but the responses that we get from Apollo Android Client is not a Json String. We can use the Object Oriented notation to fetch the information of appropriate fields but is there a way to get this response as proper Json Format.
is there a way to get this response as proper Json Format.
Not really. The big value proposition of Apollo Kotlin is typesafe models. You lose that if you’re only using Json. If you want access to the raw Json, there are certainly ways to do it with Apollo Kotlin but that’d be using the wrong tool for the Job. Something like OkHttp and sending your requests manually would do the job equally well.