[−][src]Function kubos_app::query
pub fn query(
config: &ServiceConfig,
query: &str,
timeout: Option<Duration>
) -> Result<Value, Error>
Execute a GraphQL query against a running KubOS Service using UDP.
Returns the parsed JSON result as a serde_json::Value on success
Arguments
config
- The configuration information for the service which should be queriedquery
- The raw GraphQL query as a stringtimeout
- The timeout provided to the UDP socket. Note: This function will block whenNone
is provided here
Examples
use kubos_app::*; use std::time::Duration; let request = r#"{ ping }"#; let result = query(&ServiceConfig::new_from_path("radio-service", "/home/kubos/config.toml".to_owned()), request, Some(Duration::from_secs(1)))?; let data = result.get("ping").unwrap().as_str(); assert_eq!(data, Some("pong"));
use kubos_app::*; use std::time::Duration; let request = r#"{ power }"#; let result = query(&ServiceConfig::new("antenna-service"), request, Some(Duration::from_secs(1)))?; let data = result.get("power").unwrap().as_str(); assert_eq!(data, Some("ON"));