Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
euirim opened this issue Jan 26, 2021 · 4 comments · Fixed by #1649
Closed

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

euirim opened this issue Jan 26, 2021 · 4 comments · Fixed by #1649
Labels
bug Generally incorrect behavior networking-stack
Milestone

Comments

@euirim
Copy link

euirim commented Jan 26, 2021

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)
        }
     }
@euirim euirim changed the title GET queries include a non-empty request body GET queries include a Content-Type: application/json header Jan 26, 2021
@designatednerd
Copy link
Contributor

Interesting! I guess this is technically a bug, we just haven't seen any issues with this previously since even though we're sending the header we aren't actually sending the body, and it appears most servers will ignore that if there is no body.

What server are you using?

@designatednerd designatednerd added bug Generally incorrect behavior networking-stack labels Jan 27, 2021
@euirim
Copy link
Author

euirim commented Jan 27, 2021

Graphene-Python. Not a huge deal for sure, ended up creating a custom interceptor provider to strip out the header.

@designatednerd
Copy link
Contributor

I will fix this the next time I have a little time to poke at bugs (because as I said, this is technically incorrect) but you've already found my suggestion for a workaround :)

@designatednerd
Copy link
Contributor

Fix has shipped with 0.41.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Generally incorrect behavior networking-stack
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants