Skip to content

GET queries include a Content-Type: application/json header #1642

@euirim

Description

@euirim

Bug report

After using the useGETForQueries option, the ApolloClient's requests include Content-Type: application/json header that triggers a "POST body sent invalid JSON" 400 error. Querying the URL used by the client without a request body and this header results in a successful 200 response. I think this is a bug, but I may be wrong and this could be expected behavior (noob to iOS dev).

Versions

Please fill in the versions you're currently using:

  • apollo-ios SDK version: 0.40
  • Xcode version: 12.3
  • Swift version: 5.3
  • Package manager: SPM

Steps to reproduce

Network class:

import Foundation
import Apollo

class Network {
    static let shared = Network()
    
    private(set) lazy var apollo: ApolloClient = {
        let client = URLSessionClient()
        let cache = InMemoryNormalizedCache()
        let store = ApolloStore(cache: cache)
        let provider = LegacyInterceptorProvider(client: client, store: store)
        let url = URL(string: "https://XXX")!
        let transport = RequestChainNetworkTransport(
            interceptorProvider: provider,
            endpointURL: url,
            useGETForQueries: true
        )
        return ApolloClient(networkTransport: transport, store: store)
    }()
}

Run:

Network.shared.apollo.fetch(query: ArticlesQuery(page: currentPage, offset: 10)) { result in
    switch result {
        case .success(let graphQLResult):
            print("result", result)
        case .failure(let error):
            print("error", error.localizedDescription)
        }
     }

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions