async_graphql/types/
empty_subscription.rs1use std::{borrow::Cow, pin::Pin};
2
3use futures_util::stream::{self, Stream};
4
5use crate::{registry, Context, Response, ServerError, SubscriptionType};
6
7#[derive(Default, Copy, Clone)]
12pub struct EmptySubscription;
13
14impl SubscriptionType for EmptySubscription {
15 fn type_name() -> Cow<'static, str> {
16 Cow::Borrowed("EmptySubscription")
17 }
18
19 fn create_type_info(registry: &mut registry::Registry) -> String {
20 registry.create_subscription_type::<Self, _>(|_| registry::MetaType::Object {
21 name: "EmptySubscription".to_string(),
22 description: None,
23 fields: Default::default(),
24 cache_control: Default::default(),
25 extends: false,
26 shareable: false,
27 resolvable: true,
28 keys: None,
29 visible: None,
30 inaccessible: false,
31 interface_object: false,
32 tags: Default::default(),
33 is_subscription: true,
34 rust_typename: Some(std::any::type_name::<Self>()),
35 directive_invocations: Default::default(),
36 })
37 }
38
39 fn is_empty() -> bool {
40 true
41 }
42
43 fn create_field_stream<'a>(
44 &'a self,
45 _ctx: &'a Context<'_>,
46 ) -> Option<Pin<Box<dyn Stream<Item = Response> + Send + 'a>>>
47 where
48 Self: Send + Sync + 'static + Sized,
49 {
50 Some(Box::pin(stream::once(async move {
51 let err = ServerError::new("Schema is not configured for subscription.", None);
52 Response::from_errors(vec![err])
53 })))
54 }
55}