2020-04-06 05:49:39 +00:00
|
|
|
use crate::context::Environment;
|
2020-03-19 09:20:12 +00:00
|
|
|
use crate::{
|
2020-05-09 09:55:04 +00:00
|
|
|
registry, Context, ContextSelectionSet, Error, ObjectType, OutputValueType, Pos, QueryError,
|
|
|
|
Result, Schema, SubscriptionType, Type,
|
2020-03-19 09:20:12 +00:00
|
|
|
};
|
2020-04-06 05:49:39 +00:00
|
|
|
use futures::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;
|
|
|
|
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,
|
2020-04-06 05:49:39 +00:00
|
|
|
_ctx: &Context<'_>,
|
|
|
|
_schema: &Schema<Query, Mutation, Self>,
|
|
|
|
_environment: Arc<Environment>,
|
2020-05-03 08:02:46 +00:00
|
|
|
) -> Result<Pin<Box<dyn Stream<Item = Result<serde_json::Value>> + Send>>>
|
2020-04-06 05:49:39 +00:00
|
|
|
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 {
|
2020-05-05 13:06:48 +00:00
|
|
|
async fn resolve(&self, _ctx: &ContextSelectionSet<'_>, pos: Pos) -> Result<serde_json::Value> {
|
2020-04-02 02:21:04 +00:00
|
|
|
Err(Error::Query {
|
|
|
|
pos,
|
|
|
|
path: None,
|
|
|
|
err: QueryError::NotConfiguredSubscriptions,
|
|
|
|
})
|
2020-03-17 09:26:59 +00:00
|
|
|
}
|
|
|
|
}
|