Skip to content

Commit d2133a7

Browse files
committed
feat: add gzip compression
1 parent cd5c1e3 commit d2133a7

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

Sources/Common/GraphQL/GraphQLClient.swift

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import Foundation
2+
import DataCompression
23

34
public final class GraphQLClient {
45
public let endpoint: URL
@@ -34,6 +35,15 @@ public final class GraphQLClient {
3435
let gqlRequest = GraphQLRequest(query: query, variables: variables, operationName: operationName)
3536
var request = URLRequest(url: endpoint)
3637
request.httpMethod = "POST"
38+
39+
let rawData = try gqlRequest.httpBody()
40+
if let compressedData = rawData.gzip() {
41+
request.httpBody = compressedData
42+
request.setValue("gzip", forHTTPHeaderField: "Content-Encoding")
43+
} else {
44+
request.httpBody = rawData
45+
}
46+
3747
request.httpBody = try gqlRequest.httpBody()
3848

3949
print("🔹Sending request: \(String(data: request.httpBody!, encoding: .utf8) ?? "(no body)")")
@@ -42,6 +52,9 @@ public final class GraphQLClient {
4252
combinedHeaders.forEach { request.setValue($0.value, forHTTPHeaderField: $0.key) }
4353

4454
let data = try await network.send(request)
55+
56+
57+
print("GraphQL response: \(String(data: data, encoding: .utf8) ?? "(no data)")")
4558

4659
do {
4760
let envelope = try decoder.decode(GraphQLResponse<Output>.self, from: data)

0 commit comments

Comments
 (0)