async-graphql/src/types/empty_subscription.rs

69 lines
1.9 KiB
Rust
Raw Normal View History

use crate::context::Environment;
2020-03-19 09:20:12 +00:00
use crate::{
registry, Context, ContextSelectionSet, Error, ObjectType, OutputValueType, Pos, QueryError,
Result, Schema, SubscriptionType, Type,
2020-03-19 09:20:12 +00:00
};
use futures::Stream;
2020-03-17 09:26:59 +00:00
use std::borrow::Cow;
use std::pin::Pin;
use std::sync::Arc;
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::Type::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
}
2020-04-07 06:30:46 +00:00
async fn create_field_stream<Query, Mutation>(
2020-03-17 09:26:59 +00:00
&self,
_idx: usize,
_ctx: &Context<'_>,
_schema: &Schema<Query, Mutation, Self>,
_environment: Arc<Environment>,
) -> Result<Pin<Box<dyn Stream<Item = Result<serde_json::Value>> + Send>>>
where
Query: ObjectType + Send + Sync + 'static,
Mutation: ObjectType + Send + Sync + 'static,
Self: Send + Sync + 'static + Sized,
{
Err(Error::Query {
pos: Pos::default(),
path: None,
err: QueryError::NotConfiguredSubscriptions,
})
2020-03-19 09:20:12 +00:00
}
}
#[async_trait::async_trait]
impl OutputValueType for EmptySubscription {
async fn resolve(&self, _ctx: &ContextSelectionSet<'_>, pos: Pos) -> Result<serde_json::Value> {
Err(Error::Query {
pos,
path: None,
err: QueryError::NotConfiguredSubscriptions,
})
2020-03-17 09:26:59 +00:00
}
}