Apollo-ios: Incorrect code generation

Created on 26 Oct 2016  路  2Comments  路  Source: apollographql/apollo-ios

image

Portion of code:

public final class ViewerUserDataQuery: GraphQLQuery {
  public static let operationDefinition =
    "query viewerUserData($keys: [String!]) {" +
    "  viewer {" +
    "    user {" +
    "      data(keys: $keys) {" +
    "        key" +
    "        value" +
    "      }" +
    "    }" +
    "  }" +
    "}"

  public let keys: [String]?

  public init(keys: [String]? = nil) {
    self.keys = keys
  }

  public var variables: GraphQLMap? {
    return ["keys": keys] // Error here
  }

The autosuggestion corrects the issue, but re building reruns the script...

  public var variables: GraphQLMap? {
    return ["keys": keys as! Optional<JSONEncodable>]
  }
bug

Most helpful comment

Thanks for reporting this. It turns out variables of list types are currently not supported by the mechanism we use to convert a dictionary literal into a GraphQLMap. I'm actually in the process of revising this whole approach as part of adding caching support, so I'll see if I can get the relevant code merged sooner.

All 2 comments

Thanks for reporting this. It turns out variables of list types are currently not supported by the mechanism we use to convert a dictionary literal into a GraphQLMap. I'm actually in the process of revising this whole approach as part of adding caching support, so I'll see if I can get the relevant code merged sooner.

I just released version 0.4.0 of Apollo iOS, which should fix this issue. (You'll also have to update apollo-codegen to 0.9, but it will warn you if you don't.)

Please give it a try and let me know if it works for you!

Was this page helpful?
0 / 5 - 0 ratings