Skip to content

Commit

Permalink
fix: type casting in serialize
Browse files Browse the repository at this point in the history
  • Loading branch information
ZirgVoice committed Nov 27, 2024
1 parent db1d340 commit 49cce54
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 6 deletions.
2 changes: 1 addition & 1 deletion Package.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// swift-tools-version:5.5.2
// swift-tools-version:5.10
// The swift-tools-version declares the minimum version of Swift required to build this package.

import PackageDescription
Expand Down
6 changes: 5 additions & 1 deletion Sources/Pioneer/GraphQL/BuiltinTypes.swift
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,11 @@ public struct ID: Codable, ExpressibleByStringLiteral, CustomStringConvertible,
ID.self,
as: "ID",
serialize: { value, _ in
try GraphQLID.serialize(value: value)
guard let idValue = value as? ID else {
throw GraphQLError(message: "Failed to cast value \(value) to ID type")
}

return try GraphQLID.serialize(value: idValue.id)
},
parseValue: { inputValue, _ in
try GraphQLID.parseValue(value: inputValue)
Expand Down
1 change: 1 addition & 0 deletions Sources/Pioneer/Vapor/WebSocket/Pioneer+WebSocket.swift
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ public extension Pioneer {
}

/// Should upgrade callback
@Sendable
internal func shouldUpgrade(req: Request) -> EventLoopFuture<HTTPHeaders?> {
req.eventLoop.makeSucceededFuture(.init([("Sec-WebSocket-Protocol", websocketProtocol.name)]))
}
Expand Down
12 changes: 8 additions & 4 deletions Tests/PioneerTests/VaporTests/HTTPQueryTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,11 @@ final class HTTPQueryTests: XCTestCase {
let gql3 = GraphQLRequest(query: "query { error { id, name } }")
let gql4 = GraphQLRequest(query: "query { invalid }")

let app = Application(.testing)
let app = try await Application.make(.testing)
defer {
app.shutdown()
Task{
try await app.asyncShutdown()
}
}

app.middleware.use(server.vaporMiddleware(), at: .beginning)
Expand Down Expand Up @@ -181,9 +183,11 @@ final class HTTPQueryTests: XCTestCase {
let gql3 = "query=" + "query { error { id, name } }".addingPercentEncoding(withAllowedCharacters: .alphanumerics)!
let gql4 = "query=" + "query { invalid }".addingPercentEncoding(withAllowedCharacters: .alphanumerics)!

let app = Application(.testing)
let app = try await Application.make(.testing)
defer {
app.shutdown()
Task{
try await app.asyncShutdown()
}
}

app.middleware.use(server.vaporMiddleware(), at: .beginning)
Expand Down

0 comments on commit 49cce54

Please sign in to comment.