Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Directive Tests #134

Merged
merged 6 commits into from
Apr 3, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
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)
}
}
Loading