Skip to content
Closed
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Sources/Apollo/GraphQLGETTransformer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ struct GraphQLGETTransformer {
queryItems.append(URLQueryItem(name: self.queryKey, value: query))
components.queryItems = queryItems

guard let variables = self.body.jsonObject[self.variablesKey] as? [String: AnyHashable] else {
guard let variables = self.body.jsonObject[self.variablesKey] as? [AnyHashable : Any] else {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So messing around in a playground then looking at the docs for JSONSerialization I think this needs to be [String: Any] - JSON Serialization barfs if the keys aren't strings.

return components.url
}

Expand Down
14 changes: 14 additions & 0 deletions Tests/ApolloTests/GETTransformerTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,20 @@ class GETTransformerTests: XCTestCase {
XCTAssertEqual(url?.absoluteString, "http://localhost:8080/graphql?query=query%20HeroName($episode:%20Episode)%20%7B%0A%20%20hero(episode:%20$episode)%20%7B%0A%20%20%20%20__typename%0A%20%20%20%20name%0A%20%20%7D%0A%7D&variables=%7B%22episode%22:%22EMPIRE%22%7D")
}

func testEncodingQueryWithMoreThanOneParameterIncludingNonString() {
let operation = HeroNameTypeSpecificConditionalInclusionQuery(episode: .jedi, includeName: true)
let body: GraphQLMap = [
"query": operation.queryDocument,
"variables": operation.variables,
]

let transformer = GraphQLGETTransformer(body: body, url: self.url)

let url = transformer.createGetURL()

XCTAssertEqual(url?.absoluteString, "http://localhost:8080/graphql?query=query%20HeroNameTypeSpecificConditionalInclusion($episode:%20Episode,%20$includeName:%20Boolean!)%20%7B%0A%20%20hero(episode:%20$episode)%20%7B%0A%20%20%20%20__typename%0A%20%20%20%20name%20@include(if:%20$includeName)%0A%20%20%20%20...%20on%20Droid%20%7B%0A%20%20%20%20%20%20name%0A%20%20%20%20%7D%0A%20%20%7D%0A%7D&variables=%7B%22includeName%22:true,%22episode%22:%22JEDI%22%7D")
}

func testEncodingQueryWithNullDefaultParameter() {
let operation = HeroNameQuery()
let body: GraphQLMap = [
Expand Down