2020-09-14 01:46:22 +00:00
|
|
|
use crate::{registry, Context, Error, Pos, QueryError, Result, SubscriptionType, Type};
|
2020-09-13 17:52:36 +00:00
|
|
|
use futures::{stream, Stream};
|
2020-03-17 09:26:59 +00:00
|
|
|
use std::borrow::Cow;
|
2020-04-06 05:49:39 +00:00
|
|
|
use std::pin::Pin;
|
2020-03-17 09:26:59 +00:00
|
|
|
|
2020-03-17 11:11:14 +00:00
|
|
|
/// Empty subscription
|
|
|
|
///
|
|
|
|
/// Only the parameters used to construct the Schema, representing an unconfigured subscription.
|
2020-08-28 06:19:35 +00:00
|
|
|
#[derive(Default, Copy, Clone)]
|
2020-03-19 09:20:12 +00:00
|
|
|
pub struct EmptySubscription;
|
2020-03-17 09:26:59 +00:00
|
|
|
|
2020-03-19 09:20:12 +00:00
|
|
|
impl Type for EmptySubscription {
|
2020-03-17 09:26:59 +00:00
|
|
|
fn type_name() -> Cow<'static, str> {
|
|
|
|
Cow::Borrowed("EmptyMutation")
|
|
|
|
}
|
|
|
|
|
|
|
|
fn create_type_info(registry: &mut registry::Registry) -> String {
|
2020-05-15 02:08:37 +00:00
|
|
|
registry.create_type::<Self, _>(|_| registry::MetaType::Object {
|
2020-03-19 09:20:12 +00:00
|
|
|
name: "EmptySubscription".to_string(),
|
2020-03-17 09:26:59 +00:00
|
|
|
description: None,
|
|
|
|
fields: Default::default(),
|
2020-03-22 08:45:59 +00:00
|
|
|
cache_control: Default::default(),
|
2020-04-09 14:03:09 +00:00
|
|
|
extends: false,
|
|
|
|
keys: None,
|
2020-03-17 09:26:59 +00:00
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-03-19 09:20:12 +00:00
|
|
|
impl SubscriptionType for EmptySubscription {
|
|
|
|
fn is_empty() -> bool {
|
|
|
|
true
|
|
|
|
}
|
|
|
|
|
2020-09-13 17:52:36 +00:00
|
|
|
fn create_field_stream<'a>(
|
|
|
|
&'a self,
|
|
|
|
_ctx: &'a Context<'a>,
|
|
|
|
) -> Pin<Box<dyn Stream<Item = Result<serde_json::Value>> + Send + 'a>>
|
2020-04-06 05:49:39 +00:00
|
|
|
where
|
|
|
|
Self: Send + Sync + 'static + Sized,
|
|
|
|
{
|
2020-09-13 17:52:36 +00:00
|
|
|
Box::pin(stream::once(async {
|
|
|
|
Err(Error::Query {
|
|
|
|
pos: Pos::default(),
|
|
|
|
path: None,
|
|
|
|
err: QueryError::NotConfiguredSubscriptions,
|
|
|
|
})
|
|
|
|
}))
|
2020-03-19 09:20:12 +00:00
|
|
|
}
|
|
|
|
}
|