apollographql / apollo-kotlin

:rocket:  A strongly-typed, caching GraphQL client for the JVM, Android, and Kotlin multiplatform.
https://www.apollographql.com/docs/kotlin
MIT License
3.76k stars 653 forks source link

API of `query(Q).execute()` in code is different from the one in docs #4092

Closed simPod closed 2 years ago

simPod commented 2 years ago

Summary I'm trying to migrate from v2 to v3 so I took ApolloClient and want to execute query. However, the execute() method requires me to provide completion

image

but looking at execute() method it looks like it accepts no args

image

image

Tried to actually build that fails

        final var response = apolloClient.query(query).execute();
                                                      ^
  required: Continuation<? super ApolloResponse<D#1>>
  found:    no arguments
  reason: actual and formal argument lists differ in length
  where D#1,D#2 are type-variables:
    D#1 extends com.apollographql.apollo3.api.Query.Data declared in method <D#1>execute(Query<D#1>)
    D#2 extends com.apollographql.apollo3.api.Operation.Data declared in class ApolloCall

Version JDK 17

com.apollographql.apollo3:apollo-runtime:3.3.+ -> 3.3.0

martinbonnin commented 2 years ago

Hi 👋 Looks like you're using Java ? If that's the case, you're safest bet is to use the RxJava interop:

ApolloCall<MyQuery.Data> queryCall = client.query(new MyQuery());
Single<ApolloResponse<MyQuery.Data>> queryResponse = Rx2Apollo.single(queryCall);
queryResponse.subscribe( /* ... */ );

This is because version 3 exposes coroutine APIs first so they are easier to use in Kotlin. But the side effect of that is that it is more cumbersome in java.

If you're not in a rush, I'd recommend waiting a bit before you migrate do 3.x. We have some plans to expose a better Java API that should give you more idiomatic APIs

simPod commented 2 years ago

I'll track the mentioned issue thank. Thanks!