Apollo-ios: Extra argument 'configuration' in call

Created on 23 Sep 2019  路  2Comments  路  Source: apollographql/apollo-ios

I try to initialise Apollo client and get error: Extra argument 'configuration' in call. What's wrong with my code:

////  Apollo Client
let apollo: ApolloClient = {

    let accessToken: String = KeychainWrapper.standard.string(forKey: "token")!

    let graphEndpoint = "https://graphqlendpoint.com/graphql"
    let authPayloads = ["Authorization": "Bearer \(accessToken)"]
    let configuration = URLSessionConfiguration.default
    configuration.httpAdditionalHeaders = authPayloads
    let endpointURL = URL(string: graphEndpoint)!

    return ApolloClient(
        networkTransport: HTTPNetworkTransport(
            url: endpointURL,
            configuration: configuration)
    )
}()

I use Xcode Version 11.0 (11A420a)

Most helpful comment

Solved:

/// Apollo Client
let apollo: ApolloClient = {
    let configuration = URLSessionConfiguration.default
    var authValue: String? = "Bearer \(accessToken)"
    let authPayloads = ["Authorization": authValue ?? ""]
    let graphEndpoint = "https://graphqlendpoint.com/graphql"
    configuration.httpAdditionalHeaders = authPayloads
    let endpointURL = URL(string: graphEndpoint)!
    return ApolloClient(
        networkTransport: HTTPNetworkTransport( url: endpointURL,  session: URLSession(configuration: configuration))
    )
}()

All 2 comments

Solved:

/// Apollo Client
let apollo: ApolloClient = {
    let configuration = URLSessionConfiguration.default
    var authValue: String? = "Bearer \(accessToken)"
    let authPayloads = ["Authorization": authValue ?? ""]
    let graphEndpoint = "https://graphqlendpoint.com/graphql"
    configuration.httpAdditionalHeaders = authPayloads
    let endpointURL = URL(string: graphEndpoint)!
    return ApolloClient(
        networkTransport: HTTPNetworkTransport( url: endpointURL,  session: URLSession(configuration: configuration))
    )
}()

@bizmedia Thanks for posting the solution - Yes, there were some changes to HTTPNetworkTransport and it now takes a URLSession directly rather than a URLSessionConfiguration

Was this page helpful?
0 / 5 - 0 ratings