Skip to content

Commit

Permalink
Grab changes from #608 that map all keys and values in dictionary
Browse files Browse the repository at this point in the history
  • Loading branch information
designatednerd committed Jul 22, 2019
1 parent af7cd73 commit 6da5a32
Showing 1 changed file with 16 additions and 18 deletions.
34 changes: 16 additions & 18 deletions Sources/Apollo/GraphQLGETTransformer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -35,28 +35,26 @@ struct GraphQLGETTransformer {
return nil
}

guard let query = self.body.jsonObject[self.queryKey] as? String else {
return nil
}

var queryItems = components.queryItems ?? [URLQueryItem]()

queryItems.append(URLQueryItem(name: self.queryKey, value: query))
components.queryItems = queryItems
var queryItems: [URLQueryItem] = []

guard let variables = self.body.jsonObject[self.variablesKey] as? [String: Any] else {
return components.url
}

guard
let serializedData = try? JSONSerialization.dataSortedIfPossible(withJSONObject: variables),
let jsonString = String(bytes: serializedData, encoding: .utf8) else {
return components.url
do {
_ = try self.body.sorted(by: {$0.key < $1.key}).compactMap({ arg in
if let value = arg.value as? GraphQLMap {
let data = try JSONSerialization.dataSortedIfPossible(withJSONObject: value.jsonValue)
if let string = String(data: data, encoding: .utf8) {
queryItems.append(URLQueryItem(name: arg.key, value: string))
}
} else if let string = arg.value as? String {
queryItems.append(URLQueryItem(name: arg.key, value: string))
} else {
assertionFailure()
}
})
} catch {
return nil
}

queryItems.append(URLQueryItem(name: self.variablesKey, value: jsonString))
components.queryItems = queryItems

return components.url
}
}
Expand Down

0 comments on commit 6da5a32

Please sign in to comment.