use gurkle::*; use serde_json::json; use std::net::Ipv4Addr; // Important! The NetworkAddress scalar should deserialize to an Ipv4Addr from the Rust std library. type NetworkAddress = Ipv4Addr; #[derive(GraphQLRequest)] #[graphql( query_path = "tests/custom_scalars/query.graphql", schema_path = "tests/custom_scalars/schema.graphql" )] pub struct CustomScalarQuery; #[test] fn custom_scalars() { let valid_response = json!({ "address": "127.0.1.2", }); let valid_addr = serde_json::from_value::(valid_response).unwrap(); assert_eq!( valid_addr.address.unwrap(), "127.0.1.2".parse::().unwrap() ); let invalid_response = json!({ "address": "localhost", }); assert!(serde_json::from_value::(invalid_response).is_err()); }