This question was originally asked on github issues. Posted here in hopes of getting an answer.
Please tell me is it possible to somehow get information about response headers in SyncGraphQlClientInterceptor
?
The problem we are trying to solve:
There is a certain graphql server provider that returns apollo-trace-id
in the response headers. On our side, we need to log this traceID to improve observability. We can get the response header at the ClientHttpRequestInterceptor
level, but we want to log this identifier in two cases:
- If the provider's server returned an incorrect HTTP status.
- If the provider’s server returned incorrect data in the response (for example, there are some errors in the errors block of the response that do not allow this response to be considered valid).
And if the first point can be solved quite simply using ClientHttpRequestInterceptor
, then the second point can be more difficult to solve using it. The problem is that ClientHttpRequestInterceptor
does not have a deserialized response body and there is no easy way to parse it. And if we take SyncGraphQlClientInterceptor
, then there is no access to response headers due to the lack of such data in GraphQlResponse
and the transfer of this information to HttpSyncGraphQlTransport
. There are essentially two options:
- Create a certain context for storing apollo-trace-id at the
ClientHttpRequestInterceptor
level (a class with theThreadLocal
field) and then pick it up at theSyncGraphQlClientInterceptor
level. - Additionally deserialize the response body at the
ClientHttpRequestInterceptor
level and log information abouttraceID
there.
But both options, to be honest, look so-so. Maybe there are some better options that we haven't noticed?