Implements Default for Schema.

This commit is contained in:
Sunli 2020-08-28 14:19:35 +08:00
parent ca5f91aee4
commit 6a38057a22
4 changed files with 28 additions and 0 deletions

View File

@ -153,6 +153,21 @@ impl<Query, Mutation, Subscription> Clone for Schema<Query, Mutation, Subscripti
}
}
impl<Query, Mutation, Subscription> Default for Schema<Query, Mutation, Subscription>
where
Query: Default + ObjectType + Send + Sync + 'static,
Mutation: Default + ObjectType + Send + Sync + 'static,
Subscription: Default + SubscriptionType + Send + Sync + 'static,
{
fn default() -> Self {
Schema::new(
Query::default(),
Mutation::default(),
Subscription::default(),
)
}
}
impl<Query, Mutation, Subscription> Deref for Schema<Query, Mutation, Subscription>
where
Query: ObjectType + Send + Sync + 'static,

View File

@ -21,6 +21,7 @@ use std::borrow::Cow;
///
/// let schema = Schema::new(QueryRoot, EmptyMutation, EmptySubscription);
/// ```
#[derive(Default, Copy, Clone)]
pub struct EmptyMutation;
impl Type for EmptyMutation {

View File

@ -7,6 +7,7 @@ use std::pin::Pin;
/// Empty subscription
///
/// Only the parameters used to construct the Schema, representing an unconfigured subscription.
#[derive(Default, Copy, Clone)]
pub struct EmptySubscription;
impl Type for EmptySubscription {

11
tests/schema.rs Normal file
View File

@ -0,0 +1,11 @@
use async_graphql::*;
#[async_std::test]
pub async fn test_schema_default() {
#[derive(GQLSimpleObject, Default)]
struct Query;
type MySchema = Schema<Query, EmptyMutation, EmptySubscription>;
let _schema = MySchema::default();
}