diff options
| author | Christian Cleberg <[email protected]> | 2026-03-24 16:49:04 -0500 |
|---|---|---|
| committer | Christian Cleberg <[email protected]> | 2026-03-24 16:49:04 -0500 |
| commit | 1a4338ac9fa4392a3b1d04d6fe1316f4c9804802 (patch) | |
| tree | 374e1eb82f10966dd6ec33fb3bb4d7d4e4396fed | |
| parent | b4542f0295bb4cb3e0f92326ee43bd7ecc477a0e (diff) | |
| download | hutch-1a4338ac9fa4392a3b1d04d6fe1316f4c9804802.tar.gz hutch-1a4338ac9fa4392a3b1d04d6fe1316f4c9804802.tar.bz2 hutch-1a4338ac9fa4392a3b1d04d6fe1316f4c9804802.zip | |
fix: route executeGraphQLRequest through SRHTClient instead of URLSession.shared
| -rw-r--r-- | Hutch/Views/Inbox/ThreadViewModel.swift | 34 |
1 files changed, 5 insertions, 29 deletions
diff --git a/Hutch/Views/Inbox/ThreadViewModel.swift b/Hutch/Views/Inbox/ThreadViewModel.swift index 6b70a41..1c3705b 100644 --- a/Hutch/Views/Inbox/ThreadViewModel.swift +++ b/Hutch/Views/Inbox/ThreadViewModel.swift @@ -684,36 +684,12 @@ final class ThreadViewModel { query: String, variables: [String: any Sendable] ) async throws -> T { - guard let token = KeychainHelper.loadToken(), !token.isEmpty else { - throw SRHTError.unauthorized - } - - var request = URLRequest(url: SRHTService.lists.url) - request.httpMethod = "POST" - request.setValue("Bearer \(token)", forHTTPHeaderField: "Authorization") - request.setValue("application/json", forHTTPHeaderField: "Content-Type") - - let encoder = JSONEncoder() - request.httpBody = try encoder.encode( - GraphQLRequestBody( - query: query, - variables: variables.mapValues { AnyCodable($0) } - ) + try await client.execute( + service: .lists, + query: query, + variables: variables, + responseType: T.self ) - - let (data, _) = try await URLSession.shared.data(for: request) - let decoder = JSONDecoder() - decoder.dateDecodingStrategy = .srhtFlexible - let envelope = try decoder.decode(GraphQLResponse<T>.self, from: data) - if let errors = envelope.errors, !errors.isEmpty { - throw SRHTError.graphQLErrors(errors) - } - guard let payload = envelope.data else { - throw SRHTError.decodingError( - DecodingError.dataCorrupted(.init(codingPath: [], debugDescription: "No data in thread detail response")) - ) - } - return payload } private static func isRecoverableNoRows(_ error: Error) -> Bool { |
