Apollo-ios: Generic parameter 'Query' could not be inferred

Created on 25 Dec 2017  路  4Comments  路  Source: apollographql/apollo-ios

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

Most helpful comment

I got the same error.. do you know why ?

capture d ecran 2018-10-17 a 13 15 26
capture d ecran 2018-10-17 a 13 18 47

All 4 comments

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 ?

capture d ecran 2018-10-17 a 13 15 26
capture d ecran 2018-10-17 a 13 18 47

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)")
                                }

Was this page helpful?
0 / 5 - 0 ratings

Related issues

MrAlek picture MrAlek  路  3Comments

designatednerd picture designatednerd  路  3Comments

jeromeDms picture jeromeDms  路  5Comments

TarekSalama picture TarekSalama  路  4Comments

hiteshborse12 picture hiteshborse12  路  4Comments