-
Notifications
You must be signed in to change notification settings - Fork 67
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #134 from NoDevOrg/directive-tests
Add Directive Tests
- Loading branch information
Showing
3 changed files
with
95 additions
and
9 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,77 @@ | ||
@testable import Graphiti | ||
import GraphQL | ||
import NIO | ||
import XCTest | ||
|
||
class DirectiveTests: XCTestCase { | ||
private let api = StarWarsAPI() | ||
private var group = MultiThreadedEventLoopGroup(numberOfThreads: System.coreCount) | ||
|
||
deinit { | ||
try? self.group.syncShutdownGracefully() | ||
} | ||
|
||
func testSkip() throws { | ||
let query = """ | ||
query FetchHeroNameWithSkip($skipName: Boolean!) { | ||
hero { | ||
id | ||
name @skip(if: $skipName) | ||
} | ||
} | ||
""" | ||
|
||
let input: [String: Map] = [ | ||
"skipName": true, | ||
] | ||
|
||
let response = try api.execute( | ||
request: query, | ||
context: StarWarsContext(), | ||
on: group, | ||
variables: input | ||
).wait() | ||
|
||
let expected = GraphQLResult( | ||
data: [ | ||
"hero": [ | ||
"id": "2001", | ||
], | ||
] | ||
) | ||
|
||
XCTAssertEqual(response, expected) | ||
} | ||
|
||
func testInclude() throws { | ||
let query = """ | ||
query FetchHeroNameWithSkip($includeName: Boolean!) { | ||
hero { | ||
id | ||
name @include(if: $includeName) | ||
} | ||
} | ||
""" | ||
|
||
let input: [String: Map] = [ | ||
"includeName": false, | ||
] | ||
|
||
let response = try api.execute( | ||
request: query, | ||
context: StarWarsContext(), | ||
on: group, | ||
variables: input | ||
).wait() | ||
|
||
let expected = GraphQLResult( | ||
data: [ | ||
"hero": [ | ||
"id": "2001", | ||
], | ||
] | ||
) | ||
|
||
XCTAssertEqual(response, expected) | ||
} | ||
} |