title: Apollo GraphQL header always gives failure in iOS Swift
body: <p>I am working with the Apollo GraphQL client for the first time in my swift project. Followed all the steps mentioned in their document and searched over google for my issue but had no luck. I have made a query request by passing a header in my request URL but it always gives me a failure with error msg like <strong>failure(Apollo.LegacyParsingInterceptor.LegacyParsingError.couldNotParseToLegacyJSON(data: 1839 bytes))</strong>. I have referred answer of <a href="https://stackoverflow.com/questions/55395589/how-to-add-header-in-apollo-graphql-ios">link</a> but this is not worked for me. Any Help will be most appreciated.</p>
  <p>import UIKit</p>
  <p>import Apollo</p>
  <pre><code>class Network {
  
  static let shared = Network()
  
  private(set) lazy var apollo: ApolloClient = {
  
      let cache = InMemoryNormalizedCache()
      let store1 = ApolloStore(cache: cache)
      let client1 = URLSessionClient()
      let provider = NetworkInterceptorProvider(store: store1, client: client1)
      
      let url = URL(string:&quot;https://Storename.myshopify.com/admin/api/2021-04/graphql&quot;)!
      
      let requestChainTransport = RequestChainNetworkTransport(interceptorProvider: provider,endpointURL: url)
      
      return ApolloClient(networkTransport: requestChainTransport,
                          store: store1)
  }()}
  
  
  class RequestOrderDetailInterceptor: ApolloInterceptor {
  
  func interceptAsync&lt;Operation: GraphQLOperation&gt;(
      chain: RequestChain,
      request: HTTPRequest&lt;Operation&gt;,
      response: HTTPResponse&lt;Operation&gt;?,
      completion: @escaping (Result&lt;GraphQLResult&lt;Operation.Data&gt;, Error&gt;) -&gt; Void) {
      
      request.addHeader(name: &quot;X-Shopify-Access-Token&quot;, value: &quot;MyToken&quot;)
      print( &quot;Outgoing request: \(request)&quot;)
      chain.proceedAsync(request: request,
                         response: response,
                         completion: completion)
  }
  </code></pre>
  <p>}</p>
  <pre><code>class ResponseOrderDetailInterceptor: ApolloInterceptor {
  
  enum ResponseLoggingError: Error {
      case notYetReceived
  }
  
  func interceptAsync&lt;Operation: GraphQLOperation&gt;(
      chain: RequestChain,
      request: HTTPRequest&lt;Operation&gt;,
      response: HTTPResponse&lt;Operation&gt;?,
      completion: @escaping (Result&lt;GraphQLResult&lt;Operation.Data&gt;, Error&gt;) -&gt; Void) {
  
      request.addHeader(name: &quot;X-Shopify-Access-Token&quot;, value: &quot;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&quot;)
  
      defer {
  
          chain.proceedAsync(request: request,
                             response: response,
                             completion: completion)
  
      }
  
      guard let receivedResponse = response else {
          chain.handleErrorAsync(ResponseLoggingError.notYetReceived,
                                 request: request,
                                 response: response,
                                 completion: completion)
          return
  
      }
  
          print(&quot;HTTP Response: \(receivedResponse.httpResponse)&quot;)
  
      if let stringData = String(bytes: receivedResponse.rawData, encoding: .utf8) {
          print(&quot;Data: \(stringData)&quot;)
      } else {
          print(&quot;Could not convert data to string!&quot;)
      }
  }
  </code></pre>
  <p>}</p>
  <pre><code>struct NetworkInterceptorProvider: InterceptorProvider {
  
  // These properties will remain the same throughout the life of the `InterceptorProvider`, even though they
  // will be handed to different interceptors.
  private let store: ApolloStore
  private let client: URLSessionClient
  
  init(store: ApolloStore,
       client: URLSessionClient) {
      self.store = store
      self.client = client
  }
  
  func interceptors&lt;Operation: GraphQLOperation&gt;(for operation: Operation) -&gt; [ApolloInterceptor] {
      return [
          MaxRetryInterceptor(),
          LegacyCacheReadInterceptor(store: self.store),
          RequestOrderDetailInterceptor(),
          NetworkFetchInterceptor(client: self.client),
          ResponseOrderDetailInterceptor(),
          ResponseCodeInterceptor(),
          LegacyParsingInterceptor(cacheKeyForObject: self.store.cacheKeyForObject),
          AutomaticPersistedQueryInterceptor(),
          LegacyCacheWriteInterceptor(store: self.store)
      ]
  }
  </code></pre>
  <p>}</p>
  <p>//Here I am using my apollo client to fetch records</p>
  <pre><code> func getOrderDetails(){
  
   Network.shared.apollo.fetch(query: OrderDetailsByIdQuery(id: GraphQL.ID(rawValue: &quot;Z2lkOi8vc2hvcGlmeS9PcmRlci8zNzcxODAxNjk4NDY5P2tleT1kNGRiMmVhODFlNGVlNzg1NzhhMDQ4ODI2Mzc4ZTkxMw==&quot;).rawValue))  {  result in
  
          print(result) 
  
          switch result {
  
          case .success(let graphQLResult):
             
                  print(&quot;Oreder Details:&quot;,graphQLResult.data?)
              
          case .failure(let error):
              print(&quot;Error loading data \(error.localizedDescription)&quot;)
          }
      }
  </code></pre>
  <p>}</p>