Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Get Operation name in HTTP Interceptor #5881

Closed
sonatard opened this issue May 10, 2024 · 3 comments
Closed

Get Operation name in HTTP Interceptor #5881

sonatard opened this issue May 10, 2024 · 3 comments

Comments

@sonatard
Copy link
Contributor

Question

I am using an HTTP Interceptor to include the OperationName in the query of the HTTP request to make it easier to see which query is being executed in Cloud Logging.

However, the X-APOLLO-OPERATION-NAME was removed in #5533. How can I get the OperationName in the HTTP Interceptor after apollo4 beta5?

override suspend fun intercept(
        request: HttpRequest,
        chain: HttpInterceptorChain
    ): HttpResponse {
        val operationName = request.headers.first { it.name == HEADER_APOLLO_OPERATION_NAME }.value
        return chain.proceed(
            request
                .newBuilder(url = "${request.url}?operationName=$operationName")
                .build()
        )
    }
@martinbonnin
Copy link
Contributor

Hi 👋

You can use a dedicated interceptor to add the headers back:

val apolloClient = ApolloClient.Builder()
        .serverUrl(mockServer.url())
        .addInterceptor(object : ApolloInterceptor {
          override fun <D : Operation.Data> intercept(request: ApolloRequest<D>, chain: ApolloInterceptorChain): Flow<ApolloResponse<D>> {
            return chain.proceed(request.newBuilder()
                .addHttpHeader("X-APOLLO-OPERATION-NAME", request.operation.name())
                .addHttpHeader("X-APOLLO-OPERATION-ID", request.operation.id())
                .build()
            )
          }
        })
        .build()

See migration guide for more details.

@sonatard
Copy link
Contributor Author

sonatard commented May 11, 2024

Thank you! I'm always grateful for your help.

Copy link
Contributor

Do you have any feedback for the maintainers? Please tell us by taking a one-minute survey. Your responses will help us understand Apollo Kotlin usage and allow us to serve you better.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants