reactive_graph_runtime_graphql_schema/query/
command.rs

1use async_graphql::Object;
2
3use reactive_graph_command_model::entity::Command;
4use reactive_graph_command_model::entity::CommandArg;
5
6pub struct GraphQLCommand {
7    /// The instance information.
8    pub command: Command,
9}
10
11#[Object(name = "Command")]
12impl GraphQLCommand {
13    async fn namespace(&self) -> Option<String> {
14        self.command.namespace()
15    }
16
17    async fn name(&self) -> Option<String> {
18        self.command.name()
19    }
20
21    async fn help(&self) -> Option<String> {
22        self.command.help()
23    }
24
25    async fn arguments(&self, name: Option<String>) -> Vec<GraphQLCommandArgument> {
26        match self.command.args() {
27            Ok(args) => args
28                .to_vec()
29                .into_iter()
30                .filter_map(|arg| match name.clone() {
31                    Some(name) => {
32                        if name == arg.name {
33                            Some(GraphQLCommandArgument { arg })
34                        } else {
35                            None
36                        }
37                    }
38                    None => Some(GraphQLCommandArgument { arg }),
39                })
40                .collect(),
41            Err(_) => Vec::new(),
42        }
43    }
44}
45
46pub struct GraphQLCommandArgument {
47    /// The instance information.
48    pub arg: CommandArg,
49}
50
51#[Object(name = "CommandArgument")]
52impl GraphQLCommandArgument {
53    async fn name(&self) -> String {
54        self.arg.name.clone()
55    }
56
57    async fn short(&self) -> Option<String> {
58        self.arg.short.map(|c| c.to_string())
59    }
60
61    async fn long(&self) -> Option<String> {
62        self.arg.long.clone()
63    }
64
65    async fn help(&self) -> Option<String> {
66        self.arg.help.clone()
67    }
68
69    async fn required(&self) -> bool {
70        self.arg.required
71    }
72}