-
Notifications
You must be signed in to change notification settings - Fork 722
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixes #435 Invoking Query.Data(jsonObject:) fails for queries with pa…
…rams … (#437)
- Loading branch information
1 parent
86b3b65
commit c43f880
Showing
3 changed files
with
59 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
import XCTest | ||
@testable import Apollo | ||
import ApolloTestSupport | ||
import StarWarsAPI | ||
|
||
class QueryFromJSONBuildingTests: XCTestCase { | ||
func testHeroDetailsWithFragmentQueryHuman() throws { | ||
let jsonObject = [ | ||
"hero": ["__typename": "Human", "name": "Luke Skywalker", "height": 1.72] | ||
] | ||
|
||
let data = try HeroDetailsWithFragmentQuery.Data(jsonObject: jsonObject) | ||
|
||
guard let human = data.hero?.fragments.heroDetails.asHuman else { | ||
XCTFail("Wrong type") | ||
return | ||
} | ||
|
||
XCTAssertEqual(human.height, 1.72) | ||
} | ||
|
||
func testConditionalInclusionQuery() throws { | ||
let jsonObject = [ | ||
"hero": [ | ||
"__typename": "Hero", | ||
"name": "R2-D2" | ||
] | ||
] | ||
|
||
let nameData = try HeroNameConditionalInclusionQuery.Data(jsonObject: jsonObject, variables: ["includeName" : true]) | ||
XCTAssertEqual(nameData.hero?.name, "R2-D2") | ||
|
||
let noNameData = try HeroNameConditionalInclusionQuery.Data(jsonObject: jsonObject, variables: ["includeName" : false]) | ||
XCTAssertNil(noNameData.hero?.name) | ||
} | ||
|
||
func testConditionalInclusionQueryWithoutVariables() throws { | ||
let jsonObject = [ | ||
"hero": [ | ||
"__typename": "Hero", | ||
"name": "R2-D2" | ||
] | ||
] | ||
|
||
XCTAssertThrowsError(try HeroNameConditionalInclusionQuery.Data(jsonObject: jsonObject)) { error in | ||
if case let error as GraphQLResultError = error { | ||
XCTAssertEqual(error.path, ["hero"]) | ||
} else { | ||
XCTFail("Unexpected error: \(error)") | ||
} | ||
} | ||
} | ||
} |