@@ -6,11 +6,11 @@ import Hummingbird
66import HummingbirdWebSocket
77import Logging
88
9- extension GraphQLHandler {
9+ extension GraphQLHandler where Context : WebSocketRequestContext {
1010 func handleWebSocket(
1111 inbound: WebSocketInboundStream ,
1212 outbound: WebSocketOutboundWriter ,
13- graphqlContext : GraphQLContext ,
13+ context : WebSocketRouterContext < Context > ,
1414 subProtocol: WebSocketSubProtocol ,
1515 logger: Logger
1616 ) async throws {
@@ -22,21 +22,33 @@ extension GraphQLHandler {
2222 let server = GraphQLTransportWS . Server < WebSocketInit , AsyncThrowingStream < GraphQLResult , Error > > (
2323 messenger: messenger,
2424 onExecute: { graphQLRequest in
25- try await graphql (
25+ let graphQLContextComputationInputs = GraphQLContextComputationInputs < Context > (
26+ hummingbirdRequest: context. request,
27+ hummingbirdContext: context. requestContext,
28+ graphQLRequest: graphQLRequest
29+ )
30+ let graphQLContext = try await computeContext ( graphQLContextComputationInputs)
31+ return try await graphql (
2632 schema: self . schema,
2733 request: graphQLRequest. query,
2834 rootValue: self . rootValue,
29- context: graphqlContext ,
35+ context: graphQLContext ,
3036 variableValues: graphQLRequest. variables,
3137 operationName: graphQLRequest. operationName
3238 )
3339 } ,
3440 onSubscribe: { graphQLRequest in
35- try await graphqlSubscribe (
41+ let graphQLContextComputationInputs = GraphQLContextComputationInputs < Context > (
42+ hummingbirdRequest: context. request,
43+ hummingbirdContext: context. requestContext,
44+ graphQLRequest: graphQLRequest
45+ )
46+ let graphQLContext = try await computeContext ( graphQLContextComputationInputs)
47+ return try await graphqlSubscribe (
3648 schema: self . schema,
3749 request: graphQLRequest. query,
3850 rootValue: self . rootValue,
39- context: graphqlContext ,
51+ context: graphQLContext ,
4052 variableValues: graphQLRequest. variables,
4153 operationName: graphQLRequest. operationName
4254 ) . get ( )
@@ -51,21 +63,33 @@ extension GraphQLHandler {
5163 let server = GraphQLWS . Server < WebSocketInit , AsyncThrowingStream < GraphQLResult , Error > > (
5264 messenger: messenger,
5365 onExecute: { graphQLRequest in
54- try await graphql (
66+ let graphQLContextComputationInputs = GraphQLContextComputationInputs < Context > (
67+ hummingbirdRequest: context. request,
68+ hummingbirdContext: context. requestContext,
69+ graphQLRequest: graphQLRequest
70+ )
71+ let graphQLContext = try await computeContext ( graphQLContextComputationInputs)
72+ return try await graphql (
5573 schema: self . schema,
5674 request: graphQLRequest. query,
5775 rootValue: self . rootValue,
58- context: graphqlContext ,
76+ context: graphQLContext ,
5977 variableValues: graphQLRequest. variables,
6078 operationName: graphQLRequest. operationName
6179 )
6280 } ,
6381 onSubscribe: { graphQLRequest in
64- try await graphqlSubscribe (
82+ let graphQLContextComputationInputs = GraphQLContextComputationInputs < Context > (
83+ hummingbirdRequest: context. request,
84+ hummingbirdContext: context. requestContext,
85+ graphQLRequest: graphQLRequest
86+ )
87+ let graphQLContext = try await computeContext ( graphQLContextComputationInputs)
88+ return try await graphqlSubscribe (
6589 schema: self . schema,
6690 request: graphQLRequest. query,
6791 rootValue: self . rootValue,
68- context: graphqlContext ,
92+ context: graphQLContext ,
6993 variableValues: graphQLRequest. variables,
7094 operationName: graphQLRequest. operationName
7195 ) . get ( )
0 commit comments