async-graphql/src/types/empty_mutation.rs

78 lines
1.7 KiB
Rust
Raw Normal View History

2020-03-19 09:20:12 +00:00
use crate::{
2020-03-24 10:54:22 +00:00
registry, Context, ContextSelectionSet, JsonWriter, ObjectType, OutputValueType, QueryError,
Result, Type,
2020-03-19 09:20:12 +00:00
};
2020-03-06 15:58:43 +00:00
use graphql_parser::query::Field;
2020-03-02 00:24:49 +00:00
use std::borrow::Cow;
2020-03-09 10:05:52 +00:00
/// Empty mutation
///
/// Only the parameters used to construct the Schema, representing an unconfigured mutation.
///
/// # Examples
///
/// ```rust
/// use async_graphql::*;
///
/// struct QueryRoot;
///
/// #[Object]
/// impl QueryRoot {}
///
/// fn main() {
2020-03-19 09:20:12 +00:00
/// let schema = Schema::new(QueryRoot, EmptyMutation, EmptySubscription);
2020-03-09 10:05:52 +00:00
/// }
/// ```
2020-03-19 09:20:12 +00:00
pub struct EmptyMutation;
2020-03-02 00:24:49 +00:00
2020-03-19 09:20:12 +00:00
impl Type 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 {
registry.create_type::<Self, _>(|_| registry::Type::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-03-03 03:48:00 +00:00
})
}
2020-03-02 00:24:49 +00:00
}
#[async_trait::async_trait]
2020-03-19 09:20:12 +00:00
impl ObjectType for EmptyMutation {
2020-03-05 09:06:14 +00:00
fn is_empty() -> bool {
2020-03-19 09:20:12 +00:00
true
2020-03-05 09:06:14 +00:00
}
2020-03-06 15:58:43 +00:00
2020-03-24 10:54:22 +00:00
async fn resolve_field(
&self,
_ctx: &Context<'_>,
_name: &Field,
_w: &mut JsonWriter,
) -> Result<()> {
2020-03-19 09:20:12 +00:00
unreachable!()
2020-03-06 15:58:43 +00:00
}
2020-03-07 02:39:55 +00:00
async fn resolve_inline_fragment(
&self,
_name: &str,
_ctx: &ContextSelectionSet<'_>,
2020-03-24 10:54:22 +00:00
_w: &mut JsonWriter,
2020-03-07 02:39:55 +00:00
) -> Result<()> {
2020-03-19 09:20:12 +00:00
unreachable!()
}
}
#[async_trait::async_trait]
impl OutputValueType for EmptyMutation {
2020-03-24 10:54:22 +00:00
async fn resolve(
_value: &Self,
_ctx: &ContextSelectionSet<'_>,
_w: &mut JsonWriter,
) -> Result<()> {
2020-03-21 01:32:13 +00:00
Err(QueryError::NotConfiguredMutations.into())
2020-03-07 02:39:55 +00:00
}
2020-03-05 09:06:14 +00:00
}