mirror of
https://github.com/hasura/graphql-engine.git
synced 2024-12-15 09:22:43 +03:00
Allow nulls when expecting object or array in response (#440)
<!-- Thank you for submitting this PR! :) --> ## Description Fix a bug which was causing an internal error when `null` was returned by NDC for a field of array or object type. ### Product _(Select all products this will be available in)_ - [x] community-edition - [x] cloud <!-- product : end : DO NOT REMOVE --> ### Type <!-- See changelog structure: https://github.com/hasura/graphql-engine-mono/wiki/Changelog-Guide#structure-of-our-changelog --> _(Select only one. In case of multiple, choose the most appropriate)_ - [ ] highlight - [ ] enhancement - [x] bugfix - [ ] behaviour-change - [ ] performance-enhancement - [ ] security-fix <!-- type : end : DO NOT REMOVE --> ### Changelog entry <!-- - Add a user understandable changelog entry - Include all details needed to understand the change. Try including links to docs or issues if relevant - For Highlights start with a H4 heading (#### <entry title>) - Get the changelog entry reviewed by your team --> Fix a bug which was causing an internal error when `null` was returned by NDC for a field of array or object type. <!-- changelog-entry : end : DO NOT REMOVE --> <!-- changelog : end : DO NOT REMOVE --> V3_GIT_ORIGIN_REV_ID: 5c935ccd6720b5e5966dfa87c2e21dbb7a2b36f2
This commit is contained in:
parent
0e822cc934
commit
9a6cb644f1
@ -1,2 +1,3 @@
|
||||
{ "id": 1, "name": "Queen Mary University of London", "location": { "city": "London", "country": "UK", "campuses": ["Mile End", "Whitechapel", "Charterhouse Square", "West Smithfield"] }, "staff": [ { "first_name": "Peter", "last_name": "Landin", "specialities": ["Computer Science", "Education"], "favourite_artist_id": 1 } ], "departments": ["Humanities and Social Sciences", "Science and Engineering", "Medicine and Dentistry"] }
|
||||
{ "id": 2, "name": "Chalmers University of Technology", "location": { "city": "Gothenburg", "country": "Sweden", "campuses": ["Johanneberg", "Lindholmen"] }, "staff": [ { "first_name": "John", "last_name": "Hughes", "specialities": ["Computer Science", "Functional Programming", "Software Testing"], "favourite_artist_id": 2 }, { "first_name": "Koen", "last_name": "Claessen", "specialities": ["Computer Science", "Functional Programming", "Automated Reasoning"], "favourite_artist_id": 3 } ], "departments": ["Architecture and Civil Engineering", "Computer Science and Engineering", "Electrical Engineering", "Physics", "Industrial and Materials Science"] }
|
||||
{ "id": 2, "name": "Chalmers University of Technology", "location": { "city": "Gothenburg", "country": "Sweden", "campuses": ["Johanneberg", "Lindholmen"] }, "staff": [ { "first_name": "John", "last_name": "Hughes", "specialities": ["Computer Science", "Functional Programming", "Software Testing"], "favourite_artist_id": 2 }, { "first_name": "Koen", "last_name": "Claessen", "specialities": ["Computer Science", "Functional Programming", "Automated Reasoning"], "favourite_artist_id": 3 } ], "departments": ["Architecture and Civil Engineering", "Computer Science and Engineering", "Electrical Engineering", "Physics", "Industrial and Materials Science"] }
|
||||
{ "id": 3, "name": "University of Nowhere", "location": null, "staff": null, "departments": ["nothing", null]}
|
@ -246,7 +246,9 @@ pub fn process_field_selection_as_list(
|
||||
value: json::Value,
|
||||
selection_set: &normalized_ast::SelectionSet<'_, GDS>,
|
||||
) -> Result<json::Value, error::Error> {
|
||||
if selection_set.fields.is_empty() {
|
||||
if selection_set.fields.is_empty() || value.is_null() {
|
||||
// If selection set is empty we return the whole value without further processing.
|
||||
// If the value is null we have nothing to process so we return null.
|
||||
Ok(value)
|
||||
} else {
|
||||
let rows: Vec<IndexMap<String, ndc_models::RowFieldValue>> = json::from_value(value)?;
|
||||
@ -262,7 +264,9 @@ pub fn process_field_selection_as_object(
|
||||
value: json::Value,
|
||||
selection_set: &normalized_ast::SelectionSet<'_, GDS>,
|
||||
) -> Result<json::Value, error::Error> {
|
||||
if selection_set.fields.is_empty() {
|
||||
if selection_set.fields.is_empty() || value.is_null() {
|
||||
// If selection set is empty we return the whole value without further processing.
|
||||
// If the value is null we have nothing to process so we return null.
|
||||
Ok(value)
|
||||
} else {
|
||||
let row: IndexMap<String, ndc_models::RowFieldValue> = json::from_value(value)?;
|
||||
|
@ -198,6 +198,7 @@ fn rows_from_row_field_value(
|
||||
serde_json::Value::Object(_) => {
|
||||
serde_json::from_value(this.0).ok().map(|v| vec![v])
|
||||
}
|
||||
serde_json::Value::Null => Some(vec![]),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
|
@ -80,6 +80,17 @@
|
||||
"Physics",
|
||||
"Industrial and Materials Science"
|
||||
]
|
||||
},
|
||||
{
|
||||
"id": 3,
|
||||
"location": null,
|
||||
"location_country": null,
|
||||
"staff": null,
|
||||
"staff_first_name": null,
|
||||
"departments": [
|
||||
"nothing",
|
||||
null
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
|
@ -80,6 +80,17 @@
|
||||
"Physics",
|
||||
"Industrial and Materials Science"
|
||||
]
|
||||
},
|
||||
{
|
||||
"id": 3,
|
||||
"location": null,
|
||||
"location_country": null,
|
||||
"staff": null,
|
||||
"staff_first_name": null,
|
||||
"departments": [
|
||||
"nothing",
|
||||
null
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
|
@ -33,6 +33,9 @@
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"staff": null
|
||||
}
|
||||
]
|
||||
}
|
||||
@ -71,6 +74,9 @@
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"staff": null
|
||||
}
|
||||
]
|
||||
}
|
||||
@ -109,6 +115,9 @@
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"staff": null
|
||||
}
|
||||
]
|
||||
}
|
||||
@ -147,6 +156,9 @@
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"staff": null
|
||||
}
|
||||
]
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user