ITADN

Can Hummingbird serve a WebSocket from the same path as a Get request?

#780OpenNeedleInAJayStack 创建于 2026-02-02
For background, I'm building a package [here](https://github.com/NeedleInAJayStack/graphql-hummingbird) that integrates GraphQL schemas to Hummingbird in a standards-compliant way. My goal is to provide WebSocket *and* GET requests from a single `graphql` path. I've implemented this in a Vapor version of this package [here](https://github.com/GraphQLSwift/graphql-vapor/blob/main/Sources/GraphQLVapor/RoutesBuilder%2Bgraphql.swift#L38), for reference. My initial thought was to embed the following code into [this block](https://github.com/NeedleInAJayStack/graphql-hummingbird/blob/main/Sources/GraphQLHummingbird/Router%2Bgraphql.swift#L39) (taking inspiration from [this function](https://github.com/hummingbird-project/hummingbird-websocket/blob/main/Sources/HummingbirdWebSocket/WebSocketRouter.swift#L89) in hummingbird-websocket): ```swift let result = try await handler.shouldUpgrade(request, context) switch result { case .dontUpgrade: return .init(status: .methodNotAllowed) case .upgrade(let headers): context.webSocket.handler.withLockedValue { $0 = WebSocketHandlerReference.Value(context: context, handler: handler.handleWebsocket) } return .init(status: .ok, headers: headers) } ``` but I cannot access the `context.webSocket.handler` or the `WebSocketHandlerReference.Value` because they are `internal`. Is there a better way to accomplish this?
1 条评论