diff --git a/apple/OmnivoreKit/Sources/Services/DataService/Mutations/LeaveGroup.swift b/apple/OmnivoreKit/Sources/Services/DataService/Mutations/LeaveGroup.swift index b772a8119..b5686d87d 100644 --- a/apple/OmnivoreKit/Sources/Services/DataService/Mutations/LeaveGroup.swift +++ b/apple/OmnivoreKit/Sources/Services/DataService/Mutations/LeaveGroup.swift @@ -4,46 +4,45 @@ import Models import SwiftGraphQL public extension DataService { - func leaveGroup(groupID _: String) async throws { -// enum MutationResult { -// case saved(success: Bool) -// case error(errorMessage: String) -// } -// -// let selection = Selection { -// try $0.on( -// recommendError: .init { .error(errorMessage: try $0.errorCodes().first.toString()) }, -// recommendSuccess: .init { -// .saved(success: try $0.success()) -// } -// ) -// } -// -// let mutation = Selection.Mutation { -// try $0.recommend( -// input: .init(groupIds: groupIDs, note: OptionalArgument(note), pageId: pageID, recommendedWithHighlights: OptionalArgument(withHighlights)), -// selection: selection -// ) -// } -// -// let path = appEnvironment.graphqlPath -// let headers = networker.defaultHeaders -// -// return try await withCheckedThrowingContinuation { continuation in -// send(mutation, to: path, headers: headers) { queryResult in -// guard let payload = try? queryResult.get() else { -// continuation.resume(throwing: BasicError.message(messageText: "network error")) -// return -// } -// -// switch payload.data { -// case .saved: -// continuation.resume() -// case let .error(errorMessage: errorMessage): -// continuation.resume(throwing: BasicError.message(messageText: errorMessage)) -// } -// } -// } - throw BasicError.message(messageText: "Not Implemented") + func leaveGroup(groupID: String) async throws { + enum MutationResult { + case saved(success: Bool) + case error(errorMessage: String) + } + + let selection = Selection { + try $0.on( + leaveGroupError: .init { .error(errorMessage: try $0.errorCodes().first.toString()) }, + leaveGroupSuccess: .init { + .saved(success: try $0.success()) + } + ) + } + + let mutation = Selection.Mutation { + try $0.leaveGroup( + groupId: groupID, + selection: selection + ) + } + + let path = appEnvironment.graphqlPath + let headers = networker.defaultHeaders + + return try await withCheckedThrowingContinuation { continuation in + send(mutation, to: path, headers: headers) { queryResult in + guard let payload = try? queryResult.get() else { + continuation.resume(throwing: BasicError.message(messageText: "network error")) + return + } + + switch payload.data { + case .saved: + continuation.resume() + case let .error(errorMessage: errorMessage): + continuation.resume(throwing: BasicError.message(messageText: errorMessage)) + } + } + } } }