pub fn query(
    config: &ServiceConfig,
    query: &str,
    timeout: Option<Duration>
) -> Result<Value, Error>
Expand description

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 queried
  • query - The raw GraphQL query as a string
  • timeout - The timeout provided to the UDP socket. Note: This function will block when None 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"));