Skip to content

Commit

Permalink
Update examples
Browse files Browse the repository at this point in the history
  • Loading branch information
sunli829 committed Sep 24, 2022
1 parent b1b2e9a commit 5d29914
Show file tree
Hide file tree
Showing 3 changed files with 2 additions and 16 deletions.
8 changes: 1 addition & 7 deletions actix-web/token-from-header/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use actix_web::{
guard, http::header::HeaderMap, web, App, HttpRequest, HttpResponse, HttpServer, Result,
};
use async_graphql::{http::GraphiQLSource, Data, EmptyMutation, Schema};
use async_graphql::{http::GraphiQLSource, EmptyMutation, Schema};
use async_graphql_actix_web::{GraphQLRequest, GraphQLResponse, GraphQLSubscription};
use token::{on_connection_init, QueryRoot, SubscriptionRoot, Token, TokenSchema};

Expand Down Expand Up @@ -39,13 +39,7 @@ async fn index_ws(
req: HttpRequest,
payload: web::Payload,
) -> Result<HttpResponse> {
let mut data = Data::default();
if let Some(token) = get_token_from_headers(req.headers()) {
data.insert(token);
}

GraphQLSubscription::new(Schema::clone(&*schema))
.with_data(data)
.on_connection_init(on_connection_init)
.start(&req, payload)
}
Expand Down
9 changes: 1 addition & 8 deletions axum/token-from-header/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use async_graphql::{
http::{playground_source, GraphQLPlaygroundConfig, ALL_WEBSOCKET_PROTOCOLS},
Data, EmptyMutation, Schema,
EmptyMutation, Schema,
};
use async_graphql_axum::{GraphQLProtocol, GraphQLRequest, GraphQLResponse, GraphQLWebSocket};
use axum::{
Expand Down Expand Up @@ -40,18 +40,11 @@ async fn graphql_ws_handler(
Extension(schema): Extension<TokenSchema>,
protocol: GraphQLProtocol,
websocket: WebSocketUpgrade,
headers: HeaderMap,
) -> Response {
let mut data = Data::default();
if let Some(token) = get_token_from_headers(&headers) {
data.insert(token);
}

websocket
.protocols(ALL_WEBSOCKET_PROTOCOLS)
.on_upgrade(move |stream| {
GraphQLWebSocket::new(stream, schema.clone(), protocol)
.with_data(data)
.on_connection_init(on_connection_init)
.serve()
})
Expand Down
1 change: 0 additions & 1 deletion poem/token-from-header/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ async fn index(
#[handler]
async fn ws(
schema: Data<&TokenSchema>,
headers: &HeaderMap,
protocol: GraphQLProtocol,
websocket: WebSocket,
) -> impl IntoResponse {
Expand Down

0 comments on commit 5d29914

Please sign in to comment.