Skip to content

Commit

Permalink
- treat null responses as JSON scalars as we don't know the shape of …
Browse files Browse the repository at this point in the history
…output.
  • Loading branch information
laststylebender14 committed Sep 2, 2024
1 parent d473af2 commit 177457f
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/core/helpers/gql_type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,11 @@ pub fn is_valid_field_name(property_name: &str) -> bool {

pub fn to_gql_type(value: &Value) -> String {
match value {
Value::Null => "Empty",
Value::Null => {
// treat null values as JSON scalars as we don't know the exact shape of the
// output.
"JSON"
}
Value::Bool(_) => "Boolean",
Value::Number(_) => "Int",
Value::String(_) => "String",
Expand Down Expand Up @@ -81,7 +85,7 @@ mod test {
assert_eq!(to_gql_type(&json!(false)), "Boolean");
assert_eq!(to_gql_type(&json!([1, 2, 3])), "List");
assert_eq!(to_gql_type(&json!({"name":"test", "age": 12})), "Object");
assert_eq!(to_gql_type(&Value::Null), "Empty");
assert_eq!(to_gql_type(&Value::Null), "JSON");

assert_eq!(to_gql_type(&json!([])), "List");
assert_eq!(to_gql_type(&json!({})), "Object");
Expand Down

0 comments on commit 177457f

Please sign in to comment.