2020-10-15 06:38:10 +00:00
|
|
|
use std::borrow::Cow;
|
|
|
|
|
2020-03-19 09:20:12 +00:00
|
|
|
use crate::{
|
2022-04-19 04:25:11 +00:00
|
|
|
parser::types::Field, registry, registry::MetaTypeId, resolver_utils::ContainerType, Context,
|
|
|
|
ContextSelectionSet, ObjectType, OutputType, Positioned, ServerError, ServerResult, Value,
|
2020-03-19 09:20:12 +00:00
|
|
|
};
|
2020-03-02 00:24:49 +00:00
|
|
|
|
2020-03-09 10:05:52 +00:00
|
|
|
/// Empty mutation
|
|
|
|
///
|
2022-04-19 04:25:11 +00:00
|
|
|
/// Only the parameters used to construct the Schema, representing an
|
|
|
|
/// unconfigured mutation.
|
2020-03-09 10:05:52 +00:00
|
|
|
///
|
|
|
|
/// # Examples
|
|
|
|
///
|
|
|
|
/// ```rust
|
|
|
|
/// use async_graphql::*;
|
|
|
|
///
|
2021-11-20 03:16:48 +00:00
|
|
|
/// struct Query;
|
2020-03-09 10:05:52 +00:00
|
|
|
///
|
2020-09-18 00:52:13 +00:00
|
|
|
/// #[Object]
|
2021-11-20 03:16:48 +00:00
|
|
|
/// impl Query {
|
2020-10-20 03:49:31 +00:00
|
|
|
/// async fn value(&self) -> i32 {
|
2020-10-22 02:11:47 +00:00
|
|
|
/// // A GraphQL Object type must define one or more fields.
|
2020-10-20 03:49:31 +00:00
|
|
|
/// 100
|
|
|
|
/// }
|
|
|
|
/// }
|
2020-03-09 10:05:52 +00:00
|
|
|
///
|
2021-11-20 03:16:48 +00:00
|
|
|
/// let schema = Schema::new(Query, EmptyMutation, EmptySubscription);
|
2020-03-09 10:05:52 +00:00
|
|
|
/// ```
|
2020-08-28 06:19:35 +00:00
|
|
|
#[derive(Default, Copy, Clone)]
|
2020-03-19 09:20:12 +00:00
|
|
|
pub struct EmptyMutation;
|
2020-03-02 00:24:49 +00:00
|
|
|
|
2021-11-09 10:52:10 +00:00
|
|
|
#[async_trait::async_trait]
|
|
|
|
impl ContainerType for EmptyMutation {
|
|
|
|
fn is_empty() -> bool {
|
|
|
|
true
|
|
|
|
}
|
|
|
|
|
|
|
|
async fn resolve_field(&self, _ctx: &Context<'_>) -> ServerResult<Option<Value>> {
|
|
|
|
Ok(None)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[async_trait::async_trait]
|
|
|
|
impl OutputType for EmptyMutation {
|
2020-03-02 00:24:49 +00:00
|
|
|
fn type_name() -> Cow<'static, str> {
|
|
|
|
Cow::Borrowed("EmptyMutation")
|
|
|
|
}
|
2020-03-03 03:48:00 +00:00
|
|
|
|
2020-03-03 11:15:18 +00:00
|
|
|
fn create_type_info(registry: &mut registry::Registry) -> String {
|
2022-03-30 12:54:49 +00:00
|
|
|
registry.create_output_type::<Self, _>(MetaTypeId::Object, |_| registry::MetaType::Object {
|
2020-03-19 09:20:12 +00:00
|
|
|
name: "EmptyMutation".to_string(),
|
2020-03-03 11:15:18 +00:00
|
|
|
description: None,
|
2020-03-08 12:35:36 +00:00
|
|
|
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-12-11 08:03:28 +00:00
|
|
|
visible: None,
|
2021-10-28 08:56:08 +00:00
|
|
|
is_subscription: false,
|
2021-11-08 01:33:20 +00:00
|
|
|
rust_typename: std::any::type_name::<Self>(),
|
2020-03-03 03:48:00 +00:00
|
|
|
})
|
|
|
|
}
|
2020-03-02 00:24:49 +00:00
|
|
|
|
2021-06-07 12:51:20 +00:00
|
|
|
async fn resolve(
|
|
|
|
&self,
|
|
|
|
_ctx: &ContextSelectionSet<'_>,
|
|
|
|
_field: &Positioned<Field>,
|
|
|
|
) -> ServerResult<Value> {
|
|
|
|
Err(ServerError::new(
|
2021-06-07 06:03:36 +00:00
|
|
|
"Schema is not configured for mutations.",
|
|
|
|
None,
|
2021-06-07 12:51:20 +00:00
|
|
|
))
|
2020-03-07 02:39:55 +00:00
|
|
|
}
|
2020-03-05 09:06:14 +00:00
|
|
|
}
|
2020-09-27 07:32:55 +00:00
|
|
|
|
2020-09-29 23:45:48 +00:00
|
|
|
impl ObjectType for EmptyMutation {}
|