Skip to content

Commit

Permalink
fix: treat null responses as JSON scalars (#2784)
Browse files Browse the repository at this point in the history
  • Loading branch information
laststylebender14 authored Sep 3, 2024
1 parent d473af2 commit 0af6293
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@ schema @server @upstream {
}

type Query {
usersAge(age: Int): Empty @http(baseURL: "https://example.com", path: "/users", query: [{key: "age", value: "{{.args.age}}"}])
usersAge(age: Int): JSON @http(baseURL: "https://example.com", path: "/users", query: [{key: "age", value: "{{.args.age}}"}])
}
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

1 comment on commit 0af6293

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Running 30s test @ http://localhost:8000/graphql

4 threads and 100 connections

Thread Stats Avg Stdev Max +/- Stdev
Latency 7.06ms 3.30ms 91.35ms 73.21%
Req/Sec 3.59k 210.28 3.97k 92.83%

428946 requests in 30.01s, 2.15GB read

Requests/sec: 14293.37

Transfer/sec: 73.36MB

Please sign in to comment.