Skip to content

Instantly share code, notes, and snippets.

@chandan-0
Created March 6, 2022 11:20
Show Gist options
  • Save chandan-0/a0877d8e11b43ce8839572a53078afa5 to your computer and use it in GitHub Desktop.
Save chandan-0/a0877d8e11b43ce8839572a53078afa5 to your computer and use it in GitHub Desktop.
//
// LearningGraphQLAPI.swift
// Learning GraphQL
//
// Created by Chandan on 06/03/22.
//
import Foundation
import Apollo
import BrightFutures
class LearningGraphQLAPI {
static let shared = LearningGraphQLAPI()
// Your get country details Query ready
func getCountryDetails(countryCode: String) -> Future<GraphQLResult<GetCountryQuery.Data>, Error> {
let promice = Promise<GraphQLResult<GetCountryQuery.Data>, Error>()
Network.shared.apollo.fetch(query: GetCountryQuery(id: countryCode)) { response in
switch response.result {
case .success(let graphQlResult):
promice.success(graphQlResult)
case .failure(let error):
promice.failure(error)
}
}
return promice.future
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment