Move websockets to http module and fix doc tests
This commit is contained in:
parent
4e8734b54b
commit
9796364348
|
@ -66,14 +66,14 @@ where
|
||||||
fn started(&mut self, ctx: &mut Self::Context) {
|
fn started(&mut self, ctx: &mut Self::Context) {
|
||||||
self.hb(ctx);
|
self.hb(ctx);
|
||||||
if let Some(initializer) = self.initializer.take() {
|
if let Some(initializer) = self.initializer.take() {
|
||||||
let (sink, stream) = async_graphql::transports::websocket::create_with_initializer(
|
let (sink, stream) = async_graphql::http::websocket::create_with_initializer(
|
||||||
&self.schema,
|
&self.schema,
|
||||||
initializer,
|
initializer,
|
||||||
);
|
);
|
||||||
ctx.add_stream(stream);
|
ctx.add_stream(stream);
|
||||||
self.sink = Some(sink);
|
self.sink = Some(sink);
|
||||||
} else {
|
} else {
|
||||||
let (sink, stream) = async_graphql::transports::websocket::create(&self.schema);
|
let (sink, stream) = async_graphql::http::websocket::create(&self.schema);
|
||||||
ctx.add_stream(stream);
|
ctx.add_stream(stream);
|
||||||
self.sink = Some(sink);
|
self.sink = Some(sink);
|
||||||
};
|
};
|
||||||
|
|
|
@ -27,14 +27,14 @@ use yansi::Paint;
|
||||||
///
|
///
|
||||||
/// ```rust,no_run
|
/// ```rust,no_run
|
||||||
///
|
///
|
||||||
/// use async_graphql::{EmptyMutation, EmptySubscription, Schema, Object};
|
/// use async_graphql::{EmptyMutation, EmptySubscription, Schema, GQLObject};
|
||||||
/// use async_graphql_rocket::{GQLRequest, GraphQL, GQLResponse};
|
/// use async_graphql_rocket::{GQLRequest, GraphQL, GQLResponse};
|
||||||
/// use rocket::{response::content, routes, State, http::Status};
|
/// use rocket::{response::content, routes, State, http::Status};
|
||||||
///
|
///
|
||||||
/// type ExampleSchema = Schema<QueryRoot, EmptyMutation, EmptySubscription>;
|
/// type ExampleSchema = Schema<QueryRoot, EmptyMutation, EmptySubscription>;
|
||||||
/// struct QueryRoot;
|
/// struct QueryRoot;
|
||||||
///
|
///
|
||||||
/// #[Object]
|
/// #[GQLObject]
|
||||||
/// impl QueryRoot {
|
/// impl QueryRoot {
|
||||||
/// #[field(desc = "Returns the sum of a and b")]
|
/// #[field(desc = "Returns the sum of a and b")]
|
||||||
/// async fn add(&self, a: i32, b: i32) -> i32 {
|
/// async fn add(&self, a: i32, b: i32) -> i32 {
|
||||||
|
|
|
@ -26,7 +26,7 @@ use tide::{
|
||||||
/// use tide::Request;
|
/// use tide::Request;
|
||||||
///
|
///
|
||||||
/// struct QueryRoot;
|
/// struct QueryRoot;
|
||||||
/// #[Object]
|
/// #[GQLObject]
|
||||||
/// impl QueryRoot {
|
/// impl QueryRoot {
|
||||||
/// #[field(desc = "Returns the sum of a and b")]
|
/// #[field(desc = "Returns the sum of a and b")]
|
||||||
/// async fn add(&self, a: i32, b: i32) -> i32 {
|
/// async fn add(&self, a: i32, b: i32) -> i32 {
|
||||||
|
|
|
@ -51,7 +51,7 @@ impl Reject for BadRequest {}
|
||||||
///
|
///
|
||||||
/// struct QueryRoot;
|
/// struct QueryRoot;
|
||||||
///
|
///
|
||||||
/// #[Object]
|
/// #[GQLObject]
|
||||||
/// impl QueryRoot {
|
/// impl QueryRoot {
|
||||||
/// #[field]
|
/// #[field]
|
||||||
/// async fn value(&self, ctx: &Context<'_>) -> i32 {
|
/// async fn value(&self, ctx: &Context<'_>) -> i32 {
|
||||||
|
@ -147,12 +147,12 @@ where
|
||||||
///
|
///
|
||||||
/// struct QueryRoot;
|
/// struct QueryRoot;
|
||||||
///
|
///
|
||||||
/// #[Object]
|
/// #[GQLObject]
|
||||||
/// impl QueryRoot {}
|
/// impl QueryRoot {}
|
||||||
///
|
///
|
||||||
/// struct SubscriptionRoot;
|
/// struct SubscriptionRoot;
|
||||||
///
|
///
|
||||||
/// #[Subscription]
|
/// #[GQLSubscription]
|
||||||
/// impl SubscriptionRoot {
|
/// impl SubscriptionRoot {
|
||||||
/// #[field]
|
/// #[field]
|
||||||
/// async fn tick(&self) -> impl Stream<Item = String> {
|
/// async fn tick(&self) -> impl Stream<Item = String> {
|
||||||
|
@ -200,7 +200,7 @@ where
|
||||||
ws.on_upgrade(move |websocket| {
|
ws.on_upgrade(move |websocket| {
|
||||||
let (mut tx, rx) = websocket.split();
|
let (mut tx, rx) = websocket.split();
|
||||||
let (mut stx, srx) =
|
let (mut stx, srx) =
|
||||||
async_graphql::transports::websocket::create_with_initializer(
|
async_graphql::http::websocket::create_with_initializer(
|
||||||
&schema,
|
&schema,
|
||||||
initializer,
|
initializer,
|
||||||
);
|
);
|
||||||
|
|
|
@ -3,6 +3,7 @@
|
||||||
mod graphiql_source;
|
mod graphiql_source;
|
||||||
mod multipart;
|
mod multipart;
|
||||||
mod playground_source;
|
mod playground_source;
|
||||||
|
pub mod websocket;
|
||||||
|
|
||||||
pub use graphiql_source::graphiql_source;
|
pub use graphiql_source::graphiql_source;
|
||||||
pub use multipart::{receive_multipart, MultipartOptions};
|
pub use multipart::{receive_multipart, MultipartOptions};
|
||||||
|
|
|
@ -115,7 +115,6 @@ mod validation;
|
||||||
pub mod extensions;
|
pub mod extensions;
|
||||||
pub mod guard;
|
pub mod guard;
|
||||||
pub mod validators;
|
pub mod validators;
|
||||||
pub use subscription::transports;
|
|
||||||
|
|
||||||
#[doc(hidden)]
|
#[doc(hidden)]
|
||||||
pub mod resolver_utils;
|
pub mod resolver_utils;
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
mod simple_broker;
|
mod simple_broker;
|
||||||
mod subscription_type;
|
mod subscription_type;
|
||||||
pub mod transports;
|
|
||||||
|
|
||||||
pub use simple_broker::SimpleBroker;
|
pub use simple_broker::SimpleBroker;
|
||||||
pub use subscription_type::{create_subscription_stream, SubscriptionType};
|
pub use subscription_type::{create_subscription_stream, SubscriptionType};
|
||||||
|
|
|
@ -1,3 +0,0 @@
|
||||||
//! Transports for subscription
|
|
||||||
|
|
||||||
pub mod websocket;
|
|
|
@ -18,7 +18,7 @@ pub async fn test_subscription_ws_transport() {
|
||||||
}
|
}
|
||||||
|
|
||||||
let schema = Schema::new(QueryRoot, EmptyMutation, SubscriptionRoot);
|
let schema = Schema::new(QueryRoot, EmptyMutation, SubscriptionRoot);
|
||||||
let (mut sink, stream) = transports::websocket::create(&schema);
|
let (mut sink, stream) = http::websocket::create(&schema);
|
||||||
futures::pin_mut!(stream);
|
futures::pin_mut!(stream);
|
||||||
|
|
||||||
sink.send(
|
sink.send(
|
||||||
|
@ -92,7 +92,7 @@ pub async fn test_subscription_ws_transport_with_token() {
|
||||||
}
|
}
|
||||||
|
|
||||||
let schema = Schema::new(QueryRoot, EmptyMutation, SubscriptionRoot);
|
let schema = Schema::new(QueryRoot, EmptyMutation, SubscriptionRoot);
|
||||||
let (mut sink, stream) = transports::websocket::create_with_initializer(&schema, |value| {
|
let (mut sink, stream) = http::websocket::create_with_initializer(&schema, |value| {
|
||||||
#[derive(serde::Deserialize)]
|
#[derive(serde::Deserialize)]
|
||||||
struct Payload {
|
struct Payload {
|
||||||
token: String,
|
token: String,
|
||||||
|
@ -187,7 +187,7 @@ pub async fn test_subscription_ws_transport_error() {
|
||||||
}
|
}
|
||||||
|
|
||||||
let schema = Schema::new(QueryRoot, EmptyMutation, SubscriptionRoot);
|
let schema = Schema::new(QueryRoot, EmptyMutation, SubscriptionRoot);
|
||||||
let (mut sink, stream) = transports::websocket::create(&schema);
|
let (mut sink, stream) = http::websocket::create(&schema);
|
||||||
futures::pin_mut!(stream);
|
futures::pin_mut!(stream);
|
||||||
|
|
||||||
sink.send(
|
sink.send(
|
||||||
|
@ -256,7 +256,7 @@ pub async fn test_query_over_websocket() {
|
||||||
}
|
}
|
||||||
|
|
||||||
let schema = Schema::new(QueryRoot, EmptyMutation, EmptySubscription);
|
let schema = Schema::new(QueryRoot, EmptyMutation, EmptySubscription);
|
||||||
let (mut sink, stream) = transports::websocket::create(&schema);
|
let (mut sink, stream) = http::websocket::create(&schema);
|
||||||
futures::pin_mut!(stream);
|
futures::pin_mut!(stream);
|
||||||
|
|
||||||
sink.send(
|
sink.send(
|
||||||
|
|
Loading…
Reference in New Issue
Block a user