async-graphql/src/types/empty_subscription.rs

52 lines
1.4 KiB
Rust
Raw Normal View History

use crate::context::QueryEnv;
2020-05-20 00:18:28 +00:00
use crate::{registry, Context, Error, Pos, QueryError, Result, SchemaEnv, SubscriptionType, Type};
use futures::Stream;
2020-03-17 09:26:59 +00:00
use std::borrow::Cow;
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-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 {
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
})
}
}
#[async_trait::async_trait]
2020-03-19 09:20:12 +00:00
impl SubscriptionType for EmptySubscription {
fn is_empty() -> bool {
true
}
async fn create_field_stream(
2020-03-17 09:26:59 +00:00
&self,
_idx: usize,
_ctx: &Context<'_>,
_schema_env: SchemaEnv,
_query_env: QueryEnv,
) -> Result<Pin<Box<dyn Stream<Item = Result<serde_json::Value>> + Send>>>
where
Self: Send + Sync + 'static + Sized,
{
Err(Error::Query {
pos: Pos::default(),
path: None,
err: QueryError::NotConfiguredSubscriptions,
})
2020-03-19 09:20:12 +00:00
}
}