Skip to content

Commit 3f15434

Browse files
Merge pull request #134 from NoDevOrg/directive-tests
Add Directive Tests
2 parents 3a4b6c5 + d0df0b1 commit 3f15434

File tree

3 files changed

+95
-9
lines changed

3 files changed

+95
-9
lines changed

Package.resolved

Lines changed: 17 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Package.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ let package = Package(
77
.library(name: "Graphiti", targets: ["Graphiti"]),
88
],
99
dependencies: [
10-
.package(url: "https://github.com/GraphQLSwift/GraphQL.git", from: "2.4.0"),
10+
.package(url: "https://github.com/GraphQLSwift/GraphQL.git", from: "2.9.2"),
1111
],
1212
targets: [
1313
.target(name: "Graphiti", dependencies: ["GraphQL"]),
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
@testable import Graphiti
2+
import GraphQL
3+
import NIO
4+
import XCTest
5+
6+
class DirectiveTests: XCTestCase {
7+
private let api = StarWarsAPI()
8+
private var group = MultiThreadedEventLoopGroup(numberOfThreads: System.coreCount)
9+
10+
deinit {
11+
try? self.group.syncShutdownGracefully()
12+
}
13+
14+
func testSkip() throws {
15+
let query = """
16+
query FetchHeroNameWithSkip($skipName: Boolean!) {
17+
hero {
18+
id
19+
name @skip(if: $skipName)
20+
}
21+
}
22+
"""
23+
24+
let input: [String: Map] = [
25+
"skipName": true,
26+
]
27+
28+
let response = try api.execute(
29+
request: query,
30+
context: StarWarsContext(),
31+
on: group,
32+
variables: input
33+
).wait()
34+
35+
let expected = GraphQLResult(
36+
data: [
37+
"hero": [
38+
"id": "2001",
39+
],
40+
]
41+
)
42+
43+
XCTAssertEqual(response, expected)
44+
}
45+
46+
func testInclude() throws {
47+
let query = """
48+
query FetchHeroNameWithSkip($includeName: Boolean!) {
49+
hero {
50+
id
51+
name @include(if: $includeName)
52+
}
53+
}
54+
"""
55+
56+
let input: [String: Map] = [
57+
"includeName": false,
58+
]
59+
60+
let response = try api.execute(
61+
request: query,
62+
context: StarWarsContext(),
63+
on: group,
64+
variables: input
65+
).wait()
66+
67+
let expected = GraphQLResult(
68+
data: [
69+
"hero": [
70+
"id": "2001",
71+
],
72+
]
73+
)
74+
75+
XCTAssertEqual(response, expected)
76+
}
77+
}

0 commit comments

Comments
 (0)