let apollo = ApolloClient(url: URL(string: "http://localhost:4000/graphql")!)
apollo.fetch(query: HelloWorldQuery) { (result, error) in
guard let data = result?.data else { return }
print(data?.hello) // "Hello world!"
}
with *.graphql
query HelloWorld($rolls: Int!)
{
getDie(numSides: 6) {
roll(numRolls: $rolls)
}
}
gives
Generic parameter 'Query' could not be inferred
Any ideas? Swift 4 + Xcode 9
You'll need to instantiate HelloWorldQuery, so you should pass something like HelloWorldQuery(rolls: 1).
Realized this shortly after and forgot to close the issue :)
Thank you
I got the same error.. do you know why ?


For those who still don't understand what to do just change
apolloClient?.fetch(query: query,
cachePolicy: .fetchIgnoringCacheData,
context: nil,
queue: DispatchQueue.main,
resultHandler: { result, error in
if let graphQLResult = result {
print("Success! Result: \(graphQLResult)")
}
if let error = error {
print("error!: \(error)")
}
to
apolloClient?.fetch(query: query,
cachePolicy: .fetchIgnoringCacheData,
context: nil,
queue: DispatchQueue.main,
resultHandler: { result in
switch result {
case .success(let graphQLResult):
print("Success! Result: \(graphQLResult)")
case .failure(let error):
print("error!: \(error)")
}
Most helpful comment
I got the same error.. do you know why ?