From ff994dc1ecfc3d11153a5241651dbb33a8f4f848 Mon Sep 17 00:00:00 2001 From: Sunli Date: Mon, 8 Nov 2021 08:44:21 +0800 Subject: [PATCH] Fix the problem that `EmptyMutation` may cause when used in `MergedObject`. #694 --- CHANGELOG.md | 4 ++++ src/types/empty_mutation.rs | 2 +- tests/merged_object.rs | 27 +++++++++++++++++++++++++++ 3 files changed, 32 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1d6e5614..c3622553 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## Unreleased +- Fix the problem that `EmptyMutation` may cause when used in `MergedObject`. [#694](https://github.com/async-graphql/async-graphql/issues/694) + +## [2.11.1] 2021-11-07 + - Add `chrono::Duration` custom scalar. [#689](https://github.com/async-graphql/async-graphql/pull/689) - Implement `From>>` for `MaybeUndefined`. - Add `MaybeUndefined::as_opt_ref`, `MaybeUndefined::as_opt_deref`, `MaybeUndefined::map`, `MaybeUndefined::map_value`, `MaybeUndefined::contains`, `MaybeUndefined::contains_value`, and `MaybeUndefined::transpose` methods. diff --git a/src/types/empty_mutation.rs b/src/types/empty_mutation.rs index da90a82c..55708628 100644 --- a/src/types/empty_mutation.rs +++ b/src/types/empty_mutation.rs @@ -57,7 +57,7 @@ impl ContainerType for EmptyMutation { } async fn resolve_field(&self, _ctx: &Context<'_>) -> ServerResult> { - unreachable!() + Ok(None) } } diff --git a/tests/merged_object.rs b/tests/merged_object.rs index e1f2402c..249188bf 100644 --- a/tests/merged_object.rs +++ b/tests/merged_object.rs @@ -401,3 +401,30 @@ pub async fn test_issue_539() { }) ) } + +#[tokio::test] +pub async fn test_issue_694() { + struct Query; + + #[Object] + impl Query { + async fn test(&self) -> bool { + true + } + } + + #[derive(MergedObject)] + pub struct QueryRoot(Query, EmptyMutation); + + let schema = Schema::new( + QueryRoot(Query, EmptyMutation), + EmptyMutation, + EmptySubscription, + ); + assert_eq!( + schema.execute("{ test }").await.into_result().unwrap().data, + value!({ + "test": true, + }) + ); +}