diff --git a/src/schema.rs b/src/schema.rs index fc47c3d7..d4fce291 100644 --- a/src/schema.rs +++ b/src/schema.rs @@ -153,6 +153,21 @@ impl Clone for Schema Default for Schema +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 Deref for Schema where Query: ObjectType + Send + Sync + 'static, diff --git a/src/types/empty_mutation.rs b/src/types/empty_mutation.rs index 06225828..83e257cc 100644 --- a/src/types/empty_mutation.rs +++ b/src/types/empty_mutation.rs @@ -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 { diff --git a/src/types/empty_subscription.rs b/src/types/empty_subscription.rs index 14c42374..9d8f71aa 100644 --- a/src/types/empty_subscription.rs +++ b/src/types/empty_subscription.rs @@ -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 { diff --git a/tests/schema.rs b/tests/schema.rs new file mode 100644 index 00000000..fc920eb8 --- /dev/null +++ b/tests/schema.rs @@ -0,0 +1,11 @@ +use async_graphql::*; + +#[async_std::test] +pub async fn test_schema_default() { + #[derive(GQLSimpleObject, Default)] + struct Query; + + type MySchema = Schema; + + let _schema = MySchema::default(); +}