Skip to content

Commit

Permalink
Merge pull request #134 from NoDevOrg/directive-tests
Browse files Browse the repository at this point in the history
Add Directive Tests
  • Loading branch information
NeedleInAJayStack authored Apr 3, 2024
2 parents 3a4b6c5 + d0df0b1 commit 3f15434
Show file tree
Hide file tree
Showing 3 changed files with 95 additions and 9 deletions.
25 changes: 17 additions & 8 deletions Package.resolved
Original file line number Diff line number Diff line change
Expand Up @@ -6,35 +6,44 @@
"repositoryURL": "https://github.com/GraphQLSwift/GraphQL.git",
"state": {
"branch": null,
"revision": "17b96ed859072fca79dd562da2a79e1bc752756f",
"version": "2.4.1"
"revision": "3cf2dbce764e7ccff8447d0b7d4634c0438449d3",
"version": "2.9.2"
}
},
{
"package": "swift-atomics",
"repositoryURL": "https://github.com/apple/swift-atomics.git",
"state": {
"branch": null,
"revision": "919eb1d83e02121cdb434c7bfc1f0c66ef17febe",
"version": "1.0.2"
"revision": "cd142fd2f64be2100422d658e7411e39489da985",
"version": "1.2.0"
}
},
{
"package": "swift-collections",
"repositoryURL": "https://github.com/apple/swift-collections",
"state": {
"branch": null,
"revision": "f504716c27d2e5d4144fa4794b12129301d17729",
"version": "1.0.3"
"revision": "94cf62b3ba8d4bed62680a282d4c25f9c63c2efb",
"version": "1.1.0"
}
},
{
"package": "swift-nio",
"repositoryURL": "https://github.com/apple/swift-nio.git",
"state": {
"branch": null,
"revision": "a16e2f54a25b2af217044e5168997009a505930f",
"version": "2.42.0"
"revision": "fc63f0cf4e55a4597407a9fc95b16a2bc44b4982",
"version": "2.64.0"
}
},
{
"package": "swift-system",
"repositoryURL": "https://github.com/apple/swift-system.git",
"state": {
"branch": null,
"revision": "025bcb1165deab2e20d4eaba79967ce73013f496",
"version": "1.2.1"
}
}
]
Expand Down
2 changes: 1 addition & 1 deletion Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ let package = Package(
.library(name: "Graphiti", targets: ["Graphiti"]),
],
dependencies: [
.package(url: "https://github.com/GraphQLSwift/GraphQL.git", from: "2.4.0"),
.package(url: "https://github.com/GraphQLSwift/GraphQL.git", from: "2.9.2"),
],
targets: [
.target(name: "Graphiti", dependencies: ["GraphQL"]),
Expand Down
77 changes: 77 additions & 0 deletions Tests/GraphitiTests/DirectiveTests/DirectiveTests.swift
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)
}
}

0 comments on commit 3f15434

Please sign in to comment.