Skip to content

Commit 9aacdbb

Browse files
committed
Cargo fmt and added Actix-Web in the release.toml
1 parent 0deb488 commit 9aacdbb

File tree

4 files changed

+47
-30
lines changed

4 files changed

+47
-30
lines changed

juniper/release.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,7 @@ pre-release-replacements = [
2727
{file="../juniper_warp/Cargo.toml", search="\\[dev-dependencies\\.juniper\\]\nversion = \"[^\"]+\"", replace="[dev-dependencies.juniper]\nversion = \"{{version}}\""},
2828
# Subscriptions
2929
{file="../juniper_subscriptions/Cargo.toml", search="juniper = \\{ version = \"[^\"]+\"", replace="juniper = { version = \"{{version}}\""},
30+
# Actix-Web
31+
{file="../juniper_actix/Cargo.toml", search="juniper = \\{ version = \"[^\"]+\"", replace="juniper = { version = \"{{version}}\""},
32+
{file="../juniper_actix/Cargo.toml", search="\\[dev-dependencies\\.juniper\\]\nversion = \"[^\"]+\"", replace="[dev-dependencies.juniper]\nversion = \"{{version}}\""},
3033
]

juniper_actix/examples/actix_subscriptions.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,16 @@ async fn graphql_subscriptions(
8787
req: HttpRequest,
8888
) -> Result<HttpResponse, Error> {
8989
let context = Database::new();
90-
unsafe { sub_handler(coordinator, context, stream, req, Some(EmptySubscriptionHandler::default())) }.await
90+
unsafe {
91+
sub_handler(
92+
coordinator,
93+
context,
94+
stream,
95+
req,
96+
Some(EmptySubscriptionHandler::default()),
97+
)
98+
}
99+
.await
91100
}
92101

93102
#[actix_rt::main]

juniper_actix/src/lib.rs

Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,9 @@ pub mod subscriptions {
231231
};
232232
use futures::{Stream, StreamExt};
233233
use juniper::{http::GraphQLRequest, InputValue, ScalarValue, SubscriptionCoordinator};
234-
use juniper_subscriptions::{message_types::*, MessageTypes, Coordinator, SubscriptionStateHandler, SubscriptionState};
234+
use juniper_subscriptions::{
235+
message_types::*, Coordinator, MessageTypes, SubscriptionState, SubscriptionStateHandler,
236+
};
235237
use serde::{Deserialize, Serialize};
236238
use std::{
237239
collections::HashMap,
@@ -260,7 +262,7 @@ pub mod subscriptions {
260262
juniper::GraphQLSubscriptionType<S, Context = Context> + Send + Sync + 'static,
261263
Subscription::TypeInfo: Send + Sync,
262264
SubHandler: SubscriptionStateHandler<Context, E> + 'static + std::marker::Unpin,
263-
E: 'static + std::error::Error + std::marker::Unpin
265+
E: 'static + std::error::Error + std::marker::Unpin,
264266
{
265267
let mut res = handshake_with_protocols(req, &["graphql-ws"])?;
266268
Ok(res.streaming(WebsocketContext::create(actor, stream)))
@@ -274,7 +276,7 @@ pub mod subscriptions {
274276
Context,
275277
S,
276278
SubHandler,
277-
E
279+
E,
278280
>(
279281
coordinator: web::Data<Coordinator<'static, Query, Mutation, Subscription, Context, S>>,
280282
context: Context,
@@ -293,7 +295,7 @@ pub mod subscriptions {
293295
juniper::GraphQLSubscriptionType<S, Context = Context> + Send + Sync + 'static,
294296
Subscription::TypeInfo: Send + Sync,
295297
SubHandler: SubscriptionStateHandler<Context, E> + 'static + std::marker::Unpin,
296-
E: 'static + std::error::Error + std::marker::Unpin
298+
E: 'static + std::error::Error + std::marker::Unpin,
297299
{
298300
start(
299301
GraphQLWSSession {
@@ -302,7 +304,7 @@ pub mod subscriptions {
302304
map_req_id_to_spawn_handle: HashMap::new(),
303305
has_started: Arc::new(AtomicBool::new(false)),
304306
handler,
305-
error_handler: std::marker::PhantomData
307+
error_handler: std::marker::PhantomData,
306308
},
307309
&req,
308310
stream,
@@ -321,14 +323,14 @@ pub mod subscriptions {
321323
juniper::GraphQLSubscriptionType<S, Context = Context> + Send + Sync + 'static,
322324
Subscription::TypeInfo: Send + Sync,
323325
SubHandler: SubscriptionStateHandler<Context, E> + 'static + std::marker::Unpin,
324-
E: 'static + std::error::Error + std::marker::Unpin
326+
E: 'static + std::error::Error + std::marker::Unpin,
325327
{
326328
pub map_req_id_to_spawn_handle: HashMap<String, SpawnHandle>,
327329
pub has_started: Arc<AtomicBool>,
328330
pub graphql_context: Context,
329331
pub coordinator: Arc<Coordinator<'static, Query, Mutation, Subscription, Context, S>>,
330332
pub handler: Option<SubHandler>,
331-
error_handler: std::marker::PhantomData<E>
333+
error_handler: std::marker::PhantomData<E>,
332334
}
333335

334336
impl<Query, Mutation, Subscription, Context, S, SubHandler, E> Actor
@@ -344,7 +346,7 @@ pub mod subscriptions {
344346
juniper::GraphQLSubscriptionType<S, Context = Context> + Send + Sync + 'static,
345347
Subscription::TypeInfo: Send + Sync,
346348
SubHandler: SubscriptionStateHandler<Context, E> + 'static + std::marker::Unpin,
347-
E: 'static + std::error::Error + std::marker::Unpin
349+
E: 'static + std::error::Error + std::marker::Unpin,
348350
{
349351
type Context = ws::WebsocketContext<
350352
GraphQLWSSession<Query, Mutation, Subscription, Context, S, SubHandler, E>,
@@ -365,7 +367,7 @@ pub mod subscriptions {
365367
juniper::GraphQLSubscriptionType<S, Context = Context> + Send + Sync + 'static,
366368
Subscription::TypeInfo: Send + Sync,
367369
SubHandler: SubscriptionStateHandler<Context, E> + 'static + std::marker::Unpin,
368-
E: 'static + std::error::Error + std::marker::Unpin
370+
E: 'static + std::error::Error + std::marker::Unpin,
369371
{
370372
fn gql_connection_ack() -> String {
371373
format!(r#"{{"type":"{}", "payload": null }}"#, GQL_CONNECTION_ACK)
@@ -476,7 +478,7 @@ pub mod subscriptions {
476478
juniper::GraphQLSubscriptionType<S, Context = Context> + Send + Sync + 'static,
477479
Subscription::TypeInfo: Send + Sync,
478480
SubHandler: SubscriptionStateHandler<Context, E> + 'static + std::marker::Unpin,
479-
E: 'static + std::error::Error + std::marker::Unpin
481+
E: 'static + std::error::Error + std::marker::Unpin,
480482
{
481483
fn handle(&mut self, msg: Result<ws::Message, ws::ProtocolError>, ctx: &mut Self::Context) {
482484
let msg = match msg {
@@ -493,14 +495,16 @@ pub mod subscriptions {
493495
let m = text.trim();
494496
let request: WsPayload<S> = match serde_json::from_str(m) {
495497
Ok(payload) => payload,
496-
Err(_) => { return; }
498+
Err(_) => {
499+
return;
500+
}
497501
};
498502
match request.type_ {
499503
MessageTypes::GqlConnectionInit => {
500504
if let Some(handler) = &self.handler {
501505
let state = SubscriptionState::OnConnection(
502506
Some(String::from(m)),
503-
&mut self.graphql_context
507+
&mut self.graphql_context,
504508
);
505509
let on_connect_result = handler.handle(state);
506510
if let Err(_err) = on_connect_result {
@@ -520,7 +524,7 @@ pub mod subscriptions {
520524
ctx.text(Self::gql_connection_ka());
521525
}
522526
});
523-
},
527+
}
524528
MessageTypes::GqlStart if has_started_value => {
525529
let coordinator = self.coordinator.clone();
526530
let mut context = self.graphql_context.clone();
@@ -556,9 +560,8 @@ pub mod subscriptions {
556560
MessageTypes::GqlStop if has_started_value => {
557561
let request_id = request.id.unwrap_or("1".to_owned());
558562
if let Some(handler) = &self.handler {
559-
let state = SubscriptionState::OnOperationComplete(
560-
&self.graphql_context
561-
);
563+
let state =
564+
SubscriptionState::OnOperationComplete(&self.graphql_context);
562565
handler.handle(state).unwrap();
563566
}
564567
match self.map_req_id_to_spawn_handle.remove(&request_id) {
@@ -577,14 +580,14 @@ pub mod subscriptions {
577580
// ))
578581
}
579582
}
580-
},
583+
}
581584
MessageTypes::GqlConnectionTerminate => {
582585
if let Some(handler) = &self.handler {
583586
let state = SubscriptionState::OnDisconnect(&self.graphql_context);
584587
handler.handle(state).unwrap();
585588
}
586589
ctx.stop();
587-
},
590+
}
588591
_ => {}
589592
}
590593
}

juniper_subscriptions/src/lib.rs

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ pub enum MessageTypes {
179179
/// Client -> Server
180180
/// Client sends this message in order to stop a running GraphQL operation execution (for example: unsubscribe)
181181
#[serde(rename = "stop")]
182-
GqlStop
182+
GqlStop,
183183
}
184184

185185
/// Subscriptions Protocol Message Type Values
@@ -199,8 +199,9 @@ pub mod message_types {
199199

200200
/// Empty SubscriptionLifeCycleHandler
201201
pub enum SubscriptionState<'a, Context>
202-
where
203-
Context: Clone + Send + Sync {
202+
where
203+
Context: Clone + Send + Sync,
204+
{
204205
/// The Subscription is at the init of the connection with the client after the
205206
/// server receives the GQL_CONNECTION_INIT message.
206207
OnConnection(Option<String>, &'a mut Context),
@@ -211,15 +212,16 @@ pub enum SubscriptionState<'a, Context>
211212
/// message to the client.
212213
OnOperationComplete(&'a Context),
213214
/// The Subscription is terminating the connection with the client.
214-
OnDisconnect(&'a Context)
215+
OnDisconnect(&'a Context),
215216
}
216217

217218
/// Trait based on the SubscriptionServer
218219
/// https://www.apollographql.com/docs/graphql-subscriptions/lifecycle-events/
219220
pub trait SubscriptionStateHandler<Context, E>
220-
where
221-
Context: Clone + Send + Sync,
222-
E: std::error::Error {
221+
where
222+
Context: Clone + Send + Sync,
223+
E: std::error::Error,
224+
{
223225
/// This function is called on when the state of the Subscription changes
224226
/// with the actual state.
225227
fn handle(&self, _state: SubscriptionState<Context>) -> Result<(), E> {
@@ -231,10 +233,10 @@ pub trait SubscriptionStateHandler<Context, E>
231233
#[derive(Default)]
232234
pub struct EmptySubscriptionHandler;
233235

234-
impl<Context> SubscriptionStateHandler<Context, std::io::Error> for EmptySubscriptionHandler
235-
where
236-
Context: Clone + Send + Sync {}
237-
236+
impl<Context> SubscriptionStateHandler<Context, std::io::Error> for EmptySubscriptionHandler where
237+
Context: Clone + Send + Sync
238+
{
239+
}
238240

239241
/// Creates [`futures::Stream`] that yields [`GraphQLResponse`]s depending on the given [`Value`]:
240242
///

0 commit comments

Comments
 (0)