async_graphql/types/
empty_mutation.rs1use std::borrow::Cow;
2
3use crate::{
4 parser::types::Field, registry, registry::MetaTypeId, resolver_utils::ContainerType, Context,
5 ContextSelectionSet, ObjectType, OutputType, Positioned, ServerError, ServerResult, Value,
6};
7
8#[derive(Default, Copy, Clone)]
31pub struct EmptyMutation;
32
33#[cfg_attr(feature = "boxed-trait", async_trait::async_trait)]
34impl ContainerType for EmptyMutation {
35 fn is_empty() -> bool {
36 true
37 }
38
39 async fn resolve_field(&self, _ctx: &Context<'_>) -> ServerResult<Option<Value>> {
40 Ok(None)
41 }
42}
43
44#[cfg_attr(feature = "boxed-trait", async_trait::async_trait)]
45impl OutputType for EmptyMutation {
46 fn type_name() -> Cow<'static, str> {
47 Cow::Borrowed("EmptyMutation")
48 }
49
50 fn create_type_info(registry: &mut registry::Registry) -> String {
51 registry.create_output_type::<Self, _>(MetaTypeId::Object, |_| registry::MetaType::Object {
52 name: "EmptyMutation".to_string(),
53 description: None,
54 fields: Default::default(),
55 cache_control: Default::default(),
56 extends: false,
57 shareable: false,
58 resolvable: true,
59 keys: None,
60 visible: None,
61 inaccessible: false,
62 interface_object: false,
63 tags: Default::default(),
64 is_subscription: false,
65 rust_typename: Some(std::any::type_name::<Self>()),
66 directive_invocations: Default::default(),
67 })
68 }
69
70 async fn resolve(
71 &self,
72 _ctx: &ContextSelectionSet<'_>,
73 _field: &Positioned<Field>,
74 ) -> ServerResult<Value> {
75 Err(ServerError::new(
76 "Schema is not configured for mutations.",
77 None,
78 ))
79 }
80}
81
82impl ObjectType for EmptyMutation {}