From 9198a845a9ee05f5871141dbbdae7a0e589e9ded Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mart=C3=ADn=20Conte=20Mac=20Donell?= Date: Wed, 8 Jan 2025 18:34:29 -0800 Subject: [PATCH] Best effort to support apollo graphql from requests (#174) --- .../source/logging/HTTPRequestInfo.swift | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/platform/swift/source/logging/HTTPRequestInfo.swift b/platform/swift/source/logging/HTTPRequestInfo.swift index 494646b8..79e5680e 100644 --- a/platform/swift/source/logging/HTTPRequestInfo.swift +++ b/platform/swift/source/logging/HTTPRequestInfo.swift @@ -15,6 +15,9 @@ enum HTTPFieldKey: String { case path = "_path" case pathTemplate = "_path_template" case query = "_query" + case graphQLOperationName = "_operation_name" + case graphQLOperationType = "_operation_type" + case graphQLOperationID = "_operation_id" } /// An object representing an HTTP request. @@ -80,6 +83,23 @@ public struct HTTPRequestInfo { String(describing: bytesExpectedToSendCount) } + // Best effort to extract graphQL operation name from the headers, this is specific + // to Apollo iOS client. + if let headers = self.headers { + if let operationName = headers["X-APOLLO-OPERATION-NAME"] { + fields[HTTPFieldKey.graphQLOperationName.rawValue] = operationName + fields[HTTPFieldKey.pathTemplate.rawValue] = "gql-\(operationName)" + } + + if let operationType = headers["X-APOLLO-OPERATION-TYPE"] { + fields[HTTPFieldKey.graphQLOperationType.rawValue] = operationType + } + + if let operationID = headers["X-APOLLO-OPERATION-ID"] { + fields[HTTPFieldKey.graphQLOperationID.rawValue] = operationID + } + } + return fields }