title: Using JSONDecoder in Apollo GraphQl client in swift language
body: <p>I used JSONDecoder to convert data into Model in graphql. I could not figure out why the decode in the code below is nil when i print?. Since I am new to graphql, I couldn't figure out whether using JSONDecoder is good. I also wanted to know if there is another alternative to use JSONDecoder in graphql?</p>
  
  <pre><code>apollo.fetch(query: LaunchListQuery()) {[weak self] result in
        switch result {
        case .success(let result):
          do {
  
            let data = try JSONSerialization.data(withJSONObject: result.data!.jsonObject, options: .allowFragments)
            let decode:LaunchesModal = try JSONDecoder().decode(LaunchesModal.self, from: data)
            print(decode)
          }catch (let error) {
            print(error.localizedDescription)
          }
        case .failure(let error):
          print("Failure! Error: \(error)")
        }
      }
  </code></pre>
  
  <p>LaunchesModel i created </p>
  
  <pre><code>struct LaunchesModal: Codable {
    var typeName:String?
    var cursor:String?
    var hasmore:Bool?
    enum CodingKeys: String,CodingKey {
      case cursor = "cursor"
      case hasmore = "hasmore"
      case typeName = "__typename"
    }
  }
  </code></pre>
  
  <p>Graphql query </p>
  
  <pre><code>query LaunchList {
   launches {
    cursor
    hasMore
   }
  }
  </code></pre>
  
  <p>API.swift file created by Apollo client </p>
  
  <pre><code>// This file was automatically generated and should not be edited.
  import Apollo
  import Foundation
  public final class LaunchListQuery: GraphQLQuery {
   /// The raw GraphQL definition of this operation.
   public let operationDefinition =
    """
    query LaunchList {
     launches {
      __typename
      cursor
      hasMore
     }
    }
    """
   public let operationName = "LaunchList"
   public init() {
   }
   public struct Data: GraphQLSelectionSet {
    public static let possibleTypes = ["Query"]
    public static let selections: [GraphQLSelection] = [
     GraphQLField("launches", type: .nonNull(.object(Launch.selections))),
    ]
    public private(set) var resultMap: ResultMap
    public init(unsafeResultMap: ResultMap) {
     self.resultMap = unsafeResultMap
    }
    public init(launches: Launch) {
     self.init(unsafeResultMap: ["__typename": "Query", "launches": launches.resultMap])
    }
    public var launches: Launch {
     get {
      return Launch(unsafeResultMap: resultMap["launches"]! as! ResultMap)
     }
     set {
      resultMap.updateValue(newValue.resultMap, forKey: "launches")
     }
    }
    public struct Launch: GraphQLSelectionSet {
     public static let possibleTypes = ["LaunchConnection"]
     public static let selections: [GraphQLSelection] = [
      GraphQLField("__typename", type: .nonNull(.scalar(String.self))),
      GraphQLField("cursor", type: .nonNull(.scalar(String.self))),
      GraphQLField("hasMore", type: .nonNull(.scalar(Bool.self))),
     ]
     public private(set) var resultMap: ResultMap
     public init(unsafeResultMap: ResultMap) {
      self.resultMap = unsafeResultMap
     }
     public init(cursor: String, hasMore: Bool) {
      self.init(unsafeResultMap: ["__typename": "LaunchConnection", "cursor": cursor, "hasMore": hasMore])
     }
     public var __typename: String {
      get {
       return resultMap["__typename"]! as! String
      }
      set {
       resultMap.updateValue(newValue, forKey: "__typename")
      }
     }
     public var cursor: String {
      get {
       return resultMap["cursor"]! as! String
      }
      set {
       resultMap.updateValue(newValue, forKey: "cursor")
      }
     }
     public var hasMore: Bool {
      get {
       return resultMap["hasMore"]! as! Bool
      }
      set {
       resultMap.updateValue(newValue, forKey: "hasMore")
      }
     }
    }
   }
  }
  </code></pre>