async-graphql icon indicating copy to clipboard operation
async-graphql copied to clipboard

Is there a void return type for async graphql mutation?

Open sarisssa opened this issue 2 years ago • 4 comments

My issue is that I want to return an empty tuple wrapped in a Result for a delete mutation. However, Rust panics that:

the trait bound (): async_graphql::OutputType is not satisfied the following other types implement trait async_graphql::OutputType

Right now I am forced to have to return a &str wrapped inside a Result.

In essence, is there a void return type for async graphql?

#[Object]
impl MutationResolver {


    async fn delete_books(
        &self,
        ctx: &Context<'_>,
        table: String,
        delete_records: Vec<BookRecordInput>,
    ) -> Result<()> {
        let data_store = ctx.data_unchecked::<Datastore>();
        let res = delete_books(data_store, table, delete_records)
            .await
            .unwrap();
        // Ok("Delete")
        Ok(())
    }
}

sarisssa avatar Jun 27 '23 20:06 sarisssa

The Void type is not defined in the GraphQL specification, so you must return a value. 🙂

sunli829 avatar Jun 28 '23 02:06 sunli829

I'm a noob here, but couldn't you make it a Option<String> and return None? If that doesn't work, you could just return the number of books deleted.

jaredtmartin avatar Jul 05 '23 15:07 jaredtmartin