Hi All, I'm hoping i can get some pointers here to...
# apollo-kotlin
i
Hi All, I'm hoping i can get some pointers here to help with my issue. We're using
4..0.0
and have
autoPersistedQueries
enabled. We're also trying to use the
@defer
directives for some high-latency fields. Now the issue, whilst we can see in the logs the incremental data, e.g the attached, we are not able to capture this in the query response itself. I've pretty much logged everything I possible can, no errors and no deferred data. Any idea what I should try or where to look?
b
Do you mean that you're getting the whole response at the end, but not incrementally?
i
The Apollo Client logging interceptor shows the data are being fetched accordingly but cant capture the response in the
toFlow().collect
handler
Copy code
.addHttpInterceptor(LoggingInterceptor(log = {
                if (isDevEnvironment() && it.contains("operationName", true) || it.contains("data", true)) {
                     println("GraphQL Client: $it")
                }
            }))
For instance, this returns null for the deferred items...
Copy code
println("FOLLOWERS...:${response.dataOrThrow().user?.onUserDeferFollowers}")
                    println("POSTS... 2:${response.dataOrThrow().user?.onUserDeferPosts}")
b
Hmm it's hard to say. Is the server public by any chance? And do you know what software it is running?
i
its not a public api. the server itself is a node/express instance running apollo. i can fetch deferred query via Apollo Studio and Stella.co edge server. I see deferred responses just fine but in the code, not able to capture this as described above
Do you/anyone have working examples?
b
a very simple example can be seen here: https://github.com/BoD/apollo-kotlin-template/tree/defer
i
That sample uses apollo-kotlin 4.2.0, and kotlin 2.1.0, does that matter? We're using kotlin 1.9.22 and apollo-kotlin 4.0.0?
think i found the cause: in your sample (which works locally), i see that no
Defer
keyword was appended to the deferred item but gql seem to be appending it for me which comes as null
b
I'm not sure what you mean by appending a
Defer
keyword?
i
so in your sample, this is how you have the deferred property:
Copy code
... on Meta @defer {
            lastModified
        }
    }
and we can see that in the log like so:
Copy code
Data(meta=Meta(__typename=Meta, onMeta=OnMeta(lastModified=2025-02-09)), resume=Resume(title=Software Engineer))
notice the onMeta
instead of just onMeta, mine was showing something like onMetaDefer
so the property on my end is not being mapped correctly. It seems the compiler is treating this differently by appending
Defer
to property name
b
That's expected. This will happen if you have both a non defer fragment on Meta (which will be generated as
onMeta
) and a deferred one
onMetaDefer
), to avoid ambiguity. If there's only one fragment, no need to disambiguate.
I think the issue may be an incompatibility with the server. Since
@defer
is not yet merged in the GraphQL spec, there has been several versions of the protocol, and Apollo Kotlin implements an early version which is compatible with the Apollo Router. But it may not be compatible with the version your server is running.
i
right even tho i could get deferred data in Apollo Studio and other playground instance like Stellate? Of course with the right header
"accept", "multipart/mixed; deferSpec=20220824"
b
if it works in Apollo Studio, I think it means the protocol is the right one and should work with Apollo Kotlin. But it's hard to guess 😅
if you share what's received (in studio you can "Copy operation as curl" and execute that) I may be able to tell if it corresponds to the expected format.
i
i see copy response, where's the
copy operation as curl
?
b
In the "..." button next to the operation
i
sorry long query :d
b
Can you paste that in the terminal and run it?
i
No cos have had to remove some sensitive data including tokens
thought you just wanted to look at things structurally?
b
I wanted to have a look at how the response looks like. The query will be the same no matter what.
i
here's what that look like with minimal dataset..
the key here is the
followers
in this case. I cant access that in apollo-kotlin, the compiler is showing
onUserDeferFollowers
b
It's expected that the compiler will generate an onXyz for all inline fragments. But it's hard to tell from here what the problem is in your case.
i
No worries! Thanks for your help. Will leave this for now and find alternative
b
All right. We would love to know if there's a bug, but it's not easy without a way to reproduce your case.