Skip to content

Add Directive Tests #134

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

Merged
merged 6 commits into from
Apr 3, 2024
Merged
Show file tree
Hide file tree
Changes from 4 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": "75cfce2d10575250821da26460a227904354b39f",
"version": "2.9.0"
}
},
{
"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": "635b2589494c97e48c62514bc8b37ced762e0a62",
"version": "2.63.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.0"),
],
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() async throws {
let query = """
query FetchHeroNameWithSkip($skipName: Boolean!) {
hero {
id
name @skip(if: $skipName)
}
}
"""

let input: [String: Map] = [
"skipName": true,
]

let response = try await api.execute(
request: query,
context: StarWarsContext(),
on: group,
variables: input
)

let expected = GraphQLResult(
data: [
"hero": [
"id": "2001",
],
]
)

XCTAssertEqual(response, expected)
}

func testInclude() async throws {
let query = """
query FetchHeroNameWithSkip($includeName: Boolean!) {
hero {
id
name @include(if: $includeName)
}
}
"""

let input: [String: Map] = [
"includeName": false,
]

let response = try await api.execute(
request: query,
context: StarWarsContext(),
on: group,
variables: input
)

let expected = GraphQLResult(
data: [
"hero": [
"id": "2001",
],
]
)

XCTAssertEqual(response, expected)
}
}