Move websockets to http module and fix doc tests

This commit is contained in:
Koxiaet 2020-09-13 07:40:34 +01:00
parent 4e8734b54b
commit 9796364348
10 changed files with 14 additions and 18 deletions

View File

@ -66,14 +66,14 @@ where
fn started(&mut self, ctx: &mut Self::Context) {
self.hb(ctx);
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,
initializer,
);
ctx.add_stream(stream);
self.sink = Some(sink);
} 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);
self.sink = Some(sink);
};

View File

@ -27,14 +27,14 @@ use yansi::Paint;
///
/// ```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 rocket::{response::content, routes, State, http::Status};
///
/// type ExampleSchema = Schema<QueryRoot, EmptyMutation, EmptySubscription>;
/// struct QueryRoot;
///
/// #[Object]
/// #[GQLObject]
/// impl QueryRoot {
/// #[field(desc = "Returns the sum of a and b")]
/// async fn add(&self, a: i32, b: i32) -> i32 {

View File

@ -26,7 +26,7 @@ use tide::{
/// use tide::Request;
///
/// struct QueryRoot;
/// #[Object]
/// #[GQLObject]
/// impl QueryRoot {
/// #[field(desc = "Returns the sum of a and b")]
/// async fn add(&self, a: i32, b: i32) -> i32 {

View File

@ -51,7 +51,7 @@ impl Reject for BadRequest {}
///
/// struct QueryRoot;
///
/// #[Object]
/// #[GQLObject]
/// impl QueryRoot {
/// #[field]
/// async fn value(&self, ctx: &Context<'_>) -> i32 {
@ -147,12 +147,12 @@ where
///
/// struct QueryRoot;
///
/// #[Object]
/// #[GQLObject]
/// impl QueryRoot {}
///
/// struct SubscriptionRoot;
///
/// #[Subscription]
/// #[GQLSubscription]
/// impl SubscriptionRoot {
/// #[field]
/// async fn tick(&self) -> impl Stream<Item = String> {
@ -200,7 +200,7 @@ where
ws.on_upgrade(move |websocket| {
let (mut tx, rx) = websocket.split();
let (mut stx, srx) =
async_graphql::transports::websocket::create_with_initializer(
async_graphql::http::websocket::create_with_initializer(
&schema,
initializer,
);

View File

@ -3,6 +3,7 @@
mod graphiql_source;
mod multipart;
mod playground_source;
pub mod websocket;
pub use graphiql_source::graphiql_source;
pub use multipart::{receive_multipart, MultipartOptions};

View File

@ -115,7 +115,6 @@ mod validation;
pub mod extensions;
pub mod guard;
pub mod validators;
pub use subscription::transports;
#[doc(hidden)]
pub mod resolver_utils;

View File

@ -1,6 +1,5 @@
mod simple_broker;
mod subscription_type;
pub mod transports;
pub use simple_broker::SimpleBroker;
pub use subscription_type::{create_subscription_stream, SubscriptionType};

View File

@ -1,3 +0,0 @@
//! Transports for subscription
pub mod websocket;

View File

@ -18,7 +18,7 @@ pub async fn test_subscription_ws_transport() {
}
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);
sink.send(
@ -92,7 +92,7 @@ pub async fn test_subscription_ws_transport_with_token() {
}
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)]
struct Payload {
token: String,
@ -187,7 +187,7 @@ pub async fn test_subscription_ws_transport_error() {
}
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);
sink.send(
@ -256,7 +256,7 @@ pub async fn test_query_over_websocket() {
}
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);
sink.send(