Skip to content

Commit

Permalink
Best effort to support apollo graphql from requests (#174)
Browse files Browse the repository at this point in the history
  • Loading branch information
Reflejo authored Jan 9, 2025
1 parent e9869be commit 9198a84
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions platform/swift/source/logging/HTTPRequestInfo.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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
}

Expand Down

0 comments on commit 9198a84

Please sign in to comment.