File tree Expand file tree Collapse file tree 3 files changed +239
-176
lines changed
examples/warp_subscriptions/src Expand file tree Collapse file tree 3 files changed +239
-176
lines changed Original file line number Diff line number Diff line change @@ -134,15 +134,6 @@ fn schema() -> Schema {
134
134
Schema :: new ( Query , EmptyMutation :: new ( ) , Subscription )
135
135
}
136
136
137
- async fn on_upgrade ( ws : warp:: ws:: WebSocket , root_node : Arc < Schema > ) {
138
- serve_graphql_ws ( ws, root_node, ConnectionConfig :: new ( Context { } ) )
139
- . map ( |r| {
140
- if let Err ( e) = r {
141
- println ! ( "Websocket error: {}" , e) ;
142
- }
143
- } ) . await ;
144
- }
145
-
146
137
#[ tokio:: main]
147
138
async fn main ( ) {
148
139
env:: set_var ( "RUST_LOG" , "warp_subscriptions" ) ;
@@ -166,12 +157,18 @@ async fn main() {
166
157
167
158
let routes = ( warp:: path ( "subscriptions" )
168
159
. and ( warp:: ws ( ) )
169
- . map (
170
- move |ws : warp:: ws:: Ws | {
171
- let root_node = root_node. clone ( ) ;
172
- ws. on_upgrade ( move |websocket| on_upgrade ( websocket, root_node. clone ( ) ) )
173
- } ,
174
- ) )
160
+ . map ( move |ws : warp:: ws:: Ws | {
161
+ let root_node = root_node. clone ( ) ;
162
+ ws. on_upgrade ( move |websocket| async move {
163
+ serve_graphql_ws ( websocket, root_node, ConnectionConfig :: new ( Context { } ) )
164
+ . map ( |r| {
165
+ if let Err ( e) = r {
166
+ println ! ( "Websocket error: {}" , e) ;
167
+ }
168
+ } )
169
+ . await
170
+ } )
171
+ } ) )
175
172
. map ( |reply| {
176
173
// TODO#584: remove this workaround
177
174
warp:: reply:: with_header ( reply, "Sec-WebSocket-Protocol" , "graphql-ws" )
You can’t perform that action at this time.
0 commit comments