-
-
Save thexande/13c7f588966c93524253359c3e151ad8 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
enum MockGraphQLQuery { | |
typealias JSONObject = [String: Any] | |
case country | |
case countries | |
var responseString: String { | |
switch self { | |
case .country: | |
return MockGraphQLQuery.countryResponseString | |
case .countries: | |
return MockGraphQLQuery.countriesResponseString | |
} | |
} | |
var responseObject: JSONObject? { | |
guard | |
let data = responseString.data(using: .utf8), | |
let object = try? JSONSerialization.jsonObject(with: data, | |
options: []) as? JSONObject | |
else { | |
return nil | |
} | |
return object | |
} | |
private static let countriesResponseString = | |
""" | |
{ | |
"data": { | |
"countries": [{ | |
"__typename": "Country", | |
"code": "USA", | |
"name": "America", | |
"emoji": "🇺🇸" | |
}] | |
} | |
} | |
""" | |
private static let countryResponseString = | |
""" | |
{ | |
"data": { | |
"country": { | |
"code":"AE", | |
"name": "United Arab Emirates", | |
"currency": "AED", | |
"phone": "971", | |
"emoji": "🇦🇪", | |
"native": "دولة الإمارات العربية المتحدة", | |
"__typename": "Country", | |
"languages": [{ | |
"name": "Arabic", | |
"__typename": "Language" | |
}], | |
"continent": { | |
"name": "Asia", | |
"__typename": "Continent" | |
} | |
} | |
} | |
} | |
""" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment