2020-03-05 00:39:56 +00:00
|
|
|
use crate::context::Data;
|
2020-05-22 03:58:49 +00:00
|
|
|
use crate::extensions::{BoxExtension, Extension, Extensions};
|
2020-03-04 06:24:44 +00:00
|
|
|
use crate::model::__DirectiveLocation;
|
2020-05-09 09:55:04 +00:00
|
|
|
use crate::parser::parse_query;
|
2020-05-21 03:36:44 +00:00
|
|
|
use crate::query::{QueryBuilder, StreamResponse};
|
2020-05-15 02:08:37 +00:00
|
|
|
use crate::registry::{MetaDirective, MetaInputValue, Registry};
|
2020-04-06 05:49:39 +00:00
|
|
|
use crate::subscription::{create_connection, create_subscription_stream, SubscriptionTransport};
|
2020-03-03 11:15:18 +00:00
|
|
|
use crate::types::QueryRoot;
|
2020-05-22 03:58:49 +00:00
|
|
|
use crate::validation::{check_rules, CheckResult, ValidationMode};
|
2020-03-29 12:02:52 +00:00
|
|
|
use crate::{
|
2020-05-22 03:58:49 +00:00
|
|
|
CacheControl, Error, ObjectType, Pos, QueryEnv, QueryError, QueryResponse, Result,
|
2020-05-26 05:35:13 +00:00
|
|
|
SubscriptionType, Type, Variables, ID,
|
2020-03-29 12:02:52 +00:00
|
|
|
};
|
2020-05-22 03:58:49 +00:00
|
|
|
use async_graphql_parser::query::{Document, OperationType};
|
2020-04-06 05:49:39 +00:00
|
|
|
use bytes::Bytes;
|
2020-03-29 12:02:52 +00:00
|
|
|
use futures::channel::mpsc;
|
2020-04-14 01:53:17 +00:00
|
|
|
use futures::Stream;
|
2020-05-16 02:05:48 +00:00
|
|
|
use indexmap::map::IndexMap;
|
2020-05-22 03:58:49 +00:00
|
|
|
use itertools::Itertools;
|
2020-04-06 05:49:39 +00:00
|
|
|
use std::any::Any;
|
2020-05-19 08:24:15 +00:00
|
|
|
use std::ops::Deref;
|
2020-03-29 12:02:52 +00:00
|
|
|
use std::sync::atomic::AtomicUsize;
|
|
|
|
use std::sync::Arc;
|
2020-03-01 10:54:34 +00:00
|
|
|
|
2020-03-29 12:02:52 +00:00
|
|
|
/// Schema builder
|
2020-05-19 08:24:15 +00:00
|
|
|
pub struct SchemaBuilder<Query, Mutation, Subscription> {
|
|
|
|
validation_mode: ValidationMode,
|
|
|
|
query: QueryRoot<Query>,
|
|
|
|
mutation: Mutation,
|
|
|
|
subscription: Subscription,
|
|
|
|
registry: Registry,
|
|
|
|
data: Data,
|
|
|
|
complexity: Option<usize>,
|
|
|
|
depth: Option<usize>,
|
|
|
|
extensions: Vec<Box<dyn Fn() -> BoxExtension + Send + Sync>>,
|
|
|
|
}
|
2020-03-29 12:02:52 +00:00
|
|
|
|
2020-03-19 09:20:12 +00:00
|
|
|
impl<Query: ObjectType, Mutation: ObjectType, Subscription: SubscriptionType>
|
2020-03-29 12:02:52 +00:00
|
|
|
SchemaBuilder<Query, Mutation, Subscription>
|
2020-03-17 09:26:59 +00:00
|
|
|
{
|
2020-04-21 12:47:48 +00:00
|
|
|
/// You can use this function to register types that are not directly referenced.
|
|
|
|
pub fn register_type<T: Type>(mut self) -> Self {
|
2020-05-19 08:24:15 +00:00
|
|
|
T::create_type_info(&mut self.registry);
|
2020-04-21 12:47:48 +00:00
|
|
|
self
|
|
|
|
}
|
|
|
|
|
2020-03-29 12:02:52 +00:00
|
|
|
/// Disable introspection query
|
|
|
|
pub fn disable_introspection(mut self) -> Self {
|
2020-05-19 08:24:15 +00:00
|
|
|
self.query.disable_introspection = true;
|
2020-03-29 12:02:52 +00:00
|
|
|
self
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Set limit complexity, Default no limit.
|
|
|
|
pub fn limit_complexity(mut self, complexity: usize) -> Self {
|
2020-05-19 08:24:15 +00:00
|
|
|
self.complexity = Some(complexity);
|
2020-03-29 12:02:52 +00:00
|
|
|
self
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Set limit complexity, Default no limit.
|
|
|
|
pub fn limit_depth(mut self, depth: usize) -> Self {
|
2020-05-19 08:24:15 +00:00
|
|
|
self.depth = Some(depth);
|
2020-03-29 12:02:52 +00:00
|
|
|
self
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Add an extension
|
|
|
|
pub fn extension<F: Fn() -> E + Send + Sync + 'static, E: Extension>(
|
|
|
|
mut self,
|
|
|
|
extension_factory: F,
|
|
|
|
) -> Self {
|
2020-05-19 08:24:15 +00:00
|
|
|
self.extensions
|
2020-03-29 12:02:52 +00:00
|
|
|
.push(Box::new(move || Box::new(extension_factory())));
|
|
|
|
self
|
|
|
|
}
|
|
|
|
|
2020-03-31 03:19:18 +00:00
|
|
|
/// Add a global data that can be accessed in the `Schema`, you access it with `Context::data`.
|
2020-03-29 12:02:52 +00:00
|
|
|
pub fn data<D: Any + Send + Sync>(mut self, data: D) -> Self {
|
2020-05-19 08:24:15 +00:00
|
|
|
self.data.insert(data);
|
2020-03-29 12:02:52 +00:00
|
|
|
self
|
|
|
|
}
|
|
|
|
|
2020-04-06 11:57:21 +00:00
|
|
|
/// Set the validation mode, default is `ValidationMode::Strict`.
|
|
|
|
pub fn validation_mode(mut self, validation_mode: ValidationMode) -> Self {
|
2020-05-19 08:24:15 +00:00
|
|
|
self.validation_mode = validation_mode;
|
2020-04-06 11:57:21 +00:00
|
|
|
self
|
|
|
|
}
|
|
|
|
|
2020-03-29 12:02:52 +00:00
|
|
|
/// Build schema.
|
|
|
|
pub fn finish(self) -> Schema<Query, Mutation, Subscription> {
|
2020-05-19 08:24:15 +00:00
|
|
|
Schema(Arc::new(SchemaInner {
|
|
|
|
validation_mode: self.validation_mode,
|
|
|
|
query: self.query,
|
|
|
|
mutation: self.mutation,
|
|
|
|
subscription: self.subscription,
|
|
|
|
complexity: self.complexity,
|
|
|
|
depth: self.depth,
|
|
|
|
extensions: self.extensions,
|
|
|
|
env: SchemaEnv(Arc::new(SchemaEnvInner {
|
|
|
|
registry: self.registry,
|
|
|
|
data: self.data,
|
|
|
|
})),
|
|
|
|
}))
|
2020-03-29 12:02:52 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-05-19 08:24:15 +00:00
|
|
|
#[doc(hidden)]
|
|
|
|
pub struct SchemaEnvInner {
|
|
|
|
pub registry: Registry,
|
|
|
|
pub data: Data,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[doc(hidden)]
|
|
|
|
#[derive(Clone)]
|
|
|
|
pub struct SchemaEnv(Arc<SchemaEnvInner>);
|
|
|
|
|
|
|
|
impl Deref for SchemaEnv {
|
|
|
|
type Target = SchemaEnvInner;
|
|
|
|
|
|
|
|
fn deref(&self) -> &Self::Target {
|
|
|
|
&self.0
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[doc(hidden)]
|
|
|
|
pub struct SchemaInner<Query, Mutation, Subscription> {
|
|
|
|
pub(crate) validation_mode: ValidationMode,
|
|
|
|
pub(crate) query: QueryRoot<Query>,
|
|
|
|
pub(crate) mutation: Mutation,
|
|
|
|
pub(crate) subscription: Subscription,
|
|
|
|
pub(crate) complexity: Option<usize>,
|
|
|
|
pub(crate) depth: Option<usize>,
|
|
|
|
pub(crate) extensions: Vec<Box<dyn Fn() -> BoxExtension + Send + Sync>>,
|
|
|
|
pub(crate) env: SchemaEnv,
|
|
|
|
}
|
|
|
|
|
2020-03-29 12:02:52 +00:00
|
|
|
/// GraphQL schema
|
2020-05-19 08:24:15 +00:00
|
|
|
pub struct Schema<Query, Mutation, Subscription>(Arc<SchemaInner<Query, Mutation, Subscription>>);
|
2020-03-29 12:02:52 +00:00
|
|
|
|
|
|
|
impl<Query, Mutation, Subscription> Clone for Schema<Query, Mutation, Subscription> {
|
|
|
|
fn clone(&self) -> Self {
|
|
|
|
Schema(self.0.clone())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-05-19 08:24:15 +00:00
|
|
|
impl<Query, Mutation, Subscription> Deref for Schema<Query, Mutation, Subscription>
|
|
|
|
where
|
|
|
|
Query: ObjectType + Send + Sync + 'static,
|
|
|
|
Mutation: ObjectType + Send + Sync + 'static,
|
|
|
|
Subscription: SubscriptionType + Send + Sync + 'static,
|
|
|
|
{
|
|
|
|
type Target = SchemaInner<Query, Mutation, Subscription>;
|
|
|
|
|
|
|
|
fn deref(&self) -> &Self::Target {
|
|
|
|
&self.0
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-03-29 12:02:52 +00:00
|
|
|
impl<Query, Mutation, Subscription> Schema<Query, Mutation, Subscription>
|
|
|
|
where
|
|
|
|
Query: ObjectType + Send + Sync + 'static,
|
|
|
|
Mutation: ObjectType + Send + Sync + 'static,
|
|
|
|
Subscription: SubscriptionType + Send + Sync + 'static,
|
|
|
|
{
|
|
|
|
/// Create a schema builder
|
2020-03-09 10:05:52 +00:00
|
|
|
///
|
|
|
|
/// The root object for the query and Mutation needs to be specified.
|
2020-03-19 09:20:12 +00:00
|
|
|
/// If there is no mutation, you can use `EmptyMutation`.
|
|
|
|
/// If there is no subscription, you can use `EmptySubscription`.
|
2020-03-29 12:02:52 +00:00
|
|
|
pub fn build(
|
|
|
|
query: Query,
|
|
|
|
mutation: Mutation,
|
|
|
|
subscription: Subscription,
|
|
|
|
) -> SchemaBuilder<Query, Mutation, Subscription> {
|
2020-03-08 12:35:36 +00:00
|
|
|
let mut registry = Registry {
|
|
|
|
types: Default::default(),
|
|
|
|
directives: Default::default(),
|
|
|
|
implements: Default::default(),
|
|
|
|
query_type: Query::type_name().to_string(),
|
|
|
|
mutation_type: if Mutation::is_empty() {
|
|
|
|
None
|
|
|
|
} else {
|
|
|
|
Some(Mutation::type_name().to_string())
|
|
|
|
},
|
2020-03-17 09:26:59 +00:00
|
|
|
subscription_type: if Subscription::is_empty() {
|
|
|
|
None
|
|
|
|
} else {
|
|
|
|
Some(Subscription::type_name().to_string())
|
|
|
|
},
|
2020-03-08 12:35:36 +00:00
|
|
|
};
|
2020-03-04 06:24:44 +00:00
|
|
|
|
2020-05-15 02:08:37 +00:00
|
|
|
registry.add_directive(MetaDirective {
|
2020-03-04 06:24:44 +00:00
|
|
|
name: "include",
|
|
|
|
description: Some("Directs the executor to include this field or fragment only when the `if` argument is true."),
|
2020-03-05 13:34:31 +00:00
|
|
|
locations: vec![
|
|
|
|
__DirectiveLocation::FIELD,
|
|
|
|
__DirectiveLocation::FRAGMENT_SPREAD,
|
|
|
|
__DirectiveLocation::INLINE_FRAGMENT
|
|
|
|
],
|
2020-03-08 12:35:36 +00:00
|
|
|
args: {
|
2020-05-16 02:05:48 +00:00
|
|
|
let mut args = IndexMap::new();
|
2020-05-15 02:08:37 +00:00
|
|
|
args.insert("if", MetaInputValue {
|
2020-03-08 12:35:36 +00:00
|
|
|
name: "if",
|
|
|
|
description: Some("Included when true."),
|
|
|
|
ty: "Boolean!".to_string(),
|
2020-03-21 01:32:13 +00:00
|
|
|
default_value: None,
|
2020-03-22 01:34:32 +00:00
|
|
|
validator: None,
|
2020-03-08 12:35:36 +00:00
|
|
|
});
|
|
|
|
args
|
|
|
|
}
|
2020-03-04 06:24:44 +00:00
|
|
|
});
|
|
|
|
|
2020-05-15 02:08:37 +00:00
|
|
|
registry.add_directive(MetaDirective {
|
2020-03-04 06:24:44 +00:00
|
|
|
name: "skip",
|
|
|
|
description: Some("Directs the executor to skip this field or fragment when the `if` argument is true."),
|
2020-03-05 13:34:31 +00:00
|
|
|
locations: vec![
|
|
|
|
__DirectiveLocation::FIELD,
|
|
|
|
__DirectiveLocation::FRAGMENT_SPREAD,
|
|
|
|
__DirectiveLocation::INLINE_FRAGMENT
|
|
|
|
],
|
2020-03-08 12:35:36 +00:00
|
|
|
args: {
|
2020-05-16 02:05:48 +00:00
|
|
|
let mut args = IndexMap::new();
|
2020-05-15 02:08:37 +00:00
|
|
|
args.insert("if", MetaInputValue {
|
2020-03-08 12:35:36 +00:00
|
|
|
name: "if",
|
|
|
|
description: Some("Skipped when true."),
|
|
|
|
ty: "Boolean!".to_string(),
|
2020-03-21 01:32:13 +00:00
|
|
|
default_value: None,
|
2020-03-22 01:34:32 +00:00
|
|
|
validator: None,
|
2020-03-08 12:35:36 +00:00
|
|
|
});
|
|
|
|
args
|
|
|
|
}
|
2020-03-04 06:24:44 +00:00
|
|
|
});
|
|
|
|
|
2020-05-19 08:24:15 +00:00
|
|
|
registry.add_directive(MetaDirective {
|
|
|
|
name: "defer",
|
|
|
|
description: None,
|
|
|
|
locations: vec![__DirectiveLocation::FIELD],
|
|
|
|
args: Default::default(),
|
|
|
|
});
|
|
|
|
|
2020-05-21 02:12:54 +00:00
|
|
|
registry.add_directive(MetaDirective {
|
|
|
|
name: "stream",
|
|
|
|
description: None,
|
|
|
|
locations: vec![__DirectiveLocation::FIELD],
|
|
|
|
args: Default::default(),
|
|
|
|
});
|
|
|
|
|
2020-03-04 06:24:44 +00:00
|
|
|
// register scalars
|
|
|
|
bool::create_type_info(&mut registry);
|
|
|
|
i32::create_type_info(&mut registry);
|
|
|
|
f32::create_type_info(&mut registry);
|
|
|
|
String::create_type_info(&mut registry);
|
2020-05-19 08:24:15 +00:00
|
|
|
ID::create_type_info(&mut registry);
|
2020-03-04 06:24:44 +00:00
|
|
|
|
2020-03-08 12:35:36 +00:00
|
|
|
QueryRoot::<Query>::create_type_info(&mut registry);
|
2020-03-05 09:06:14 +00:00
|
|
|
if !Mutation::is_empty() {
|
|
|
|
Mutation::create_type_info(&mut registry);
|
|
|
|
}
|
2020-03-17 09:26:59 +00:00
|
|
|
if !Subscription::is_empty() {
|
|
|
|
Subscription::create_type_info(&mut registry);
|
|
|
|
}
|
2020-03-04 06:24:44 +00:00
|
|
|
|
2020-04-09 14:03:09 +00:00
|
|
|
// federation
|
|
|
|
registry.create_federation_types();
|
|
|
|
|
2020-05-19 08:24:15 +00:00
|
|
|
SchemaBuilder {
|
2020-04-06 11:57:21 +00:00
|
|
|
validation_mode: ValidationMode::Strict,
|
2020-03-25 07:07:16 +00:00
|
|
|
query: QueryRoot {
|
|
|
|
inner: query,
|
|
|
|
disable_introspection: false,
|
|
|
|
},
|
2020-03-01 10:54:34 +00:00
|
|
|
mutation,
|
2020-03-17 09:26:59 +00:00
|
|
|
subscription,
|
2020-03-05 00:39:56 +00:00
|
|
|
registry,
|
|
|
|
data: Default::default(),
|
2020-03-25 07:07:16 +00:00
|
|
|
complexity: None,
|
|
|
|
depth: None,
|
2020-03-26 03:34:28 +00:00
|
|
|
extensions: Default::default(),
|
2020-05-19 08:24:15 +00:00
|
|
|
}
|
2020-03-25 07:07:16 +00:00
|
|
|
}
|
|
|
|
|
2020-03-29 12:02:52 +00:00
|
|
|
/// Create a schema
|
|
|
|
pub fn new(
|
|
|
|
query: Query,
|
|
|
|
mutation: Mutation,
|
|
|
|
subscription: Subscription,
|
|
|
|
) -> Schema<Query, Mutation, Subscription> {
|
|
|
|
Self::build(query, mutation, subscription).finish()
|
2020-03-05 00:39:56 +00:00
|
|
|
}
|
|
|
|
|
2020-05-22 03:58:49 +00:00
|
|
|
pub(crate) fn create_extensions(&self) -> Extensions {
|
|
|
|
Extensions(
|
|
|
|
self.extensions
|
|
|
|
.iter()
|
|
|
|
.map(|factory| factory())
|
|
|
|
.collect_vec(),
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2020-04-02 04:53:53 +00:00
|
|
|
/// Execute query without create the `QueryBuilder`.
|
2020-04-14 01:53:17 +00:00
|
|
|
pub async fn execute(&self, query_source: &str) -> Result<QueryResponse> {
|
|
|
|
QueryBuilder::new(query_source).execute(self).await
|
2020-04-02 04:53:53 +00:00
|
|
|
}
|
|
|
|
|
2020-05-20 00:18:28 +00:00
|
|
|
/// Execute the query without create the `QueryBuilder`, returns a stream, the first result being the query result,
|
|
|
|
/// followed by the incremental result. Only when there are `@defer` and `@stream` directives
|
|
|
|
/// in the query will there be subsequent incremental results.
|
2020-05-21 03:36:44 +00:00
|
|
|
pub async fn execute_stream(&self, query_source: &str) -> StreamResponse {
|
|
|
|
QueryBuilder::new(query_source).execute_stream(self).await
|
2020-05-20 00:18:28 +00:00
|
|
|
}
|
|
|
|
|
2020-05-22 03:58:49 +00:00
|
|
|
pub(crate) fn prepare_query(
|
|
|
|
&self,
|
|
|
|
source: &str,
|
|
|
|
) -> Result<(Document, CacheControl, Extensions)> {
|
|
|
|
// create extension instances
|
|
|
|
let extensions = self.create_extensions();
|
|
|
|
|
|
|
|
extensions.parse_start(source);
|
|
|
|
let document = extensions.log_error(parse_query(source).map_err(Into::<Error>::into))?;
|
2020-05-27 12:47:22 +00:00
|
|
|
extensions.parse_end(source, &document);
|
2020-05-22 03:58:49 +00:00
|
|
|
|
|
|
|
// check rules
|
|
|
|
extensions.validation_start();
|
|
|
|
let CheckResult {
|
|
|
|
cache_control,
|
|
|
|
complexity,
|
|
|
|
depth,
|
|
|
|
} = extensions.log_error(check_rules(
|
|
|
|
&self.env.registry,
|
|
|
|
&document,
|
|
|
|
self.validation_mode,
|
|
|
|
))?;
|
|
|
|
extensions.validation_end();
|
|
|
|
|
|
|
|
// check limit
|
|
|
|
if let Some(limit_complexity) = self.complexity {
|
|
|
|
if complexity > limit_complexity {
|
|
|
|
return extensions
|
|
|
|
.log_error(Err(QueryError::TooComplex.into_error(Pos::default())));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if let Some(limit_depth) = self.depth {
|
|
|
|
if depth > limit_depth {
|
|
|
|
return extensions.log_error(Err(QueryError::TooDeep.into_error(Pos::default())));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Ok((document, cache_control, extensions))
|
|
|
|
}
|
|
|
|
|
2020-04-06 05:49:39 +00:00
|
|
|
/// Create subscription stream, typically called inside the `SubscriptionTransport::handle_request` method
|
2020-04-07 06:30:46 +00:00
|
|
|
pub async fn create_subscription_stream(
|
2020-03-29 12:02:52 +00:00
|
|
|
&self,
|
|
|
|
source: &str,
|
|
|
|
operation_name: Option<&str>,
|
|
|
|
variables: Variables,
|
2020-04-23 02:26:16 +00:00
|
|
|
ctx_data: Option<Arc<Data>>,
|
2020-05-03 08:02:46 +00:00
|
|
|
) -> Result<impl Stream<Item = Result<serde_json::Value>> + Send> {
|
2020-05-22 03:58:49 +00:00
|
|
|
let (mut document, _, extensions) = self.prepare_query(source)?;
|
2020-03-29 12:02:52 +00:00
|
|
|
|
2020-05-12 08:27:06 +00:00
|
|
|
if !document.retain_operation(operation_name) {
|
2020-05-22 03:58:49 +00:00
|
|
|
return extensions.log_error(if let Some(name) = operation_name {
|
2020-05-12 08:27:06 +00:00
|
|
|
Err(QueryError::UnknownOperationNamed {
|
2020-05-09 09:55:04 +00:00
|
|
|
name: name.to_string(),
|
|
|
|
}
|
2020-05-12 08:27:06 +00:00
|
|
|
.into_error(Pos::default()))
|
2020-05-09 09:55:04 +00:00
|
|
|
} else {
|
2020-05-12 08:27:06 +00:00
|
|
|
Err(QueryError::MissingOperation.into_error(Pos::default()))
|
2020-05-22 03:58:49 +00:00
|
|
|
});
|
2020-05-12 08:27:06 +00:00
|
|
|
}
|
2020-03-29 12:02:52 +00:00
|
|
|
|
2020-05-18 16:03:15 +00:00
|
|
|
if document.current_operation().ty != OperationType::Subscription {
|
2020-05-22 03:58:49 +00:00
|
|
|
return extensions.log_error(Err(QueryError::NotSupported.into_error(Pos::default())));
|
2020-05-18 16:03:15 +00:00
|
|
|
}
|
|
|
|
|
2020-03-29 12:02:52 +00:00
|
|
|
let resolve_id = AtomicUsize::default();
|
2020-05-22 03:58:49 +00:00
|
|
|
let env = QueryEnv::new(
|
|
|
|
extensions,
|
|
|
|
variables,
|
|
|
|
document,
|
|
|
|
ctx_data.unwrap_or_default(),
|
|
|
|
);
|
2020-05-19 08:24:15 +00:00
|
|
|
let ctx = env.create_context(
|
|
|
|
&self.env,
|
2020-05-12 08:27:06 +00:00
|
|
|
None,
|
2020-05-19 08:24:15 +00:00
|
|
|
&env.document.current_operation().selection_set,
|
2020-05-12 08:27:06 +00:00
|
|
|
&resolve_id,
|
2020-05-19 08:24:15 +00:00
|
|
|
None,
|
2020-05-12 08:27:06 +00:00
|
|
|
);
|
2020-04-06 05:49:39 +00:00
|
|
|
let mut streams = Vec::new();
|
2020-05-22 03:58:49 +00:00
|
|
|
ctx.query_env
|
|
|
|
.extensions
|
|
|
|
.log_error(create_subscription_stream(self, env.clone(), &ctx, &mut streams).await)?;
|
2020-04-06 10:30:38 +00:00
|
|
|
Ok(futures::stream::select_all(streams))
|
2020-03-29 12:02:52 +00:00
|
|
|
}
|
|
|
|
|
2020-04-06 05:49:39 +00:00
|
|
|
/// Create subscription connection, returns `Sink` and `Stream`.
|
2020-03-31 03:19:18 +00:00
|
|
|
pub fn subscription_connection<T: SubscriptionTransport>(
|
2020-03-29 12:02:52 +00:00
|
|
|
&self,
|
|
|
|
transport: T,
|
2020-04-06 05:49:39 +00:00
|
|
|
) -> (
|
2020-05-20 07:44:59 +00:00
|
|
|
mpsc::UnboundedSender<Bytes>,
|
2020-05-26 05:35:13 +00:00
|
|
|
impl Stream<Item = Bytes> + Unpin,
|
2020-04-06 05:49:39 +00:00
|
|
|
) {
|
2020-04-23 06:52:22 +00:00
|
|
|
create_connection(self.clone(), transport)
|
2020-03-29 12:02:52 +00:00
|
|
|
}
|
2020-03-01 10:54:34 +00:00
|
|
|
}
|