Hi, I am trying to code a small project for myself to learn Apollo iOS client but I am running into questions with the API.switft
.
What I understand is that the file includes some reusable struct which maps my server answer.
My client does a simple login query to github, with the following:
query Login {
viewer {
__typename
login
name
}
}
API.swift
was generated using Apollo codegen. This part was easy. I can make a call, adding my GH token, and the call is successful.
private func checkLogin() {
Network.shared.apollo.fetch(query: LoginQuery()) { result in
switch result {
case .success(let graphQLResult):
print(graphQLResult)
case .failure(let error):
print("Failure! Error: \(error)")
}
}
}
This does not populate for free my struct LoginQuery
. The option, simple, I could think of is
case .success(let graphQLResult):
if let currentUser: LoginQuery.Data.Viewer = graphQLResult.data?.viewer {
print(currentUser.name!)
}
But I do not understand if this is the intended way or best practice.
Thanks
LM