async-graphql/docs/en/src/define_input_object.md

843 B

InputObject

You can use an Object as an argument, and GraphQL calls it an InputObject. The definition of InputObject is similar to SimpleObject, but SimpleObject can only be used as output and InputObject can only be used as input.

InputObject doesn't need a #[field] for each field, every field is an InputValue. You can add optional #[field] attributes to add descriptions or rename the field.

use async_graphql::*;

#[InputObject]
struct Coordinate {
    latitude: f64,

    #[field(desc = "...")]
    longitude: f64
}

struct Mutation;

#[Object]
impl Mutation {
    async fn users_at_location(&self, coordinate: Coordinate, radius: f64) -> Vec<User> {
        // Writes coordination to database.
        // ...
    }
}