Projects STRLCPY graphql-engine Commits 9a6cb644
🤬
  • 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
  • Loading...
  • David Overton committed with hasura-bot 1 month ago
    9a6cb644
    1 parent 0e822cc9
Revision indexing in progress... (symbol navigation in revisions will be accurate after indexed)
  • ■ ■ ■ ■ ■
    v3/crates/custom-connector/data/institutions.json
    1 1  { "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"] }
    2 2  { "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"] }
     3 +{ "id": 3, "name": "University of Nowhere", "location": null, "staff": null, "departments": ["nothing", null]}
  • ■ ■ ■ ■ ■
    v3/crates/engine/src/execute/process_response.rs
    skipped 245 lines
    246 246   value: json::Value,
    247 247   selection_set: &normalized_ast::SelectionSet<'_, GDS>,
    248 248  ) -> Result<json::Value, error::Error> {
    249  - if selection_set.fields.is_empty() {
     249 + if selection_set.fields.is_empty() || value.is_null() {
     250 + // If selection set is empty we return the whole value without further processing.
     251 + // If the value is null we have nothing to process so we return null.
    250 252   Ok(value)
    251 253   } else {
    252 254   let rows: Vec<IndexMap<String, ndc_models::RowFieldValue>> = json::from_value(value)?;
    skipped 9 lines
    262 264   value: json::Value,
    263 265   selection_set: &normalized_ast::SelectionSet<'_, GDS>,
    264 266  ) -> Result<json::Value, error::Error> {
    265  - if selection_set.fields.is_empty() {
     267 + if selection_set.fields.is_empty() || value.is_null() {
     268 + // If selection set is empty we return the whole value without further processing.
     269 + // If the value is null we have nothing to process so we return null.
    266 270   Ok(value)
    267 271   } else {
    268 272   let row: IndexMap<String, ndc_models::RowFieldValue> = json::from_value(value)?;
    skipped 172 lines
  • ■ ■ ■ ■ ■
    v3/crates/engine/src/execute/remote_joins/collect.rs
    skipped 197 lines
    198 198   serde_json::Value::Object(_) => {
    199 199   serde_json::from_value(this.0).ok().map(|v| vec![v])
    200 200   }
     201 + serde_json::Value::Null => Some(vec![]),
    201 202   _ => None,
    202 203   }
    203 204   }
    skipped 98 lines
  • ■ ■ ■ ■ ■ ■
    v3/crates/engine/tests/execute/models/select_many/nested_select/expected.json
    skipped 79 lines
    80 80   "Physics",
    81 81   "Industrial and Materials Science"
    82 82   ]
     83 + },
     84 + {
     85 + "id": 3,
     86 + "location": null,
     87 + "location_country": null,
     88 + "staff": null,
     89 + "staff_first_name": null,
     90 + "departments": [
     91 + "nothing",
     92 + null
     93 + ]
    83 94   }
    84 95   ]
    85 96   }
    skipped 1 lines
  • ■ ■ ■ ■ ■ ■
    v3/crates/engine/tests/execute/models/select_many/nested_select/no_explicit_type_mapping/expected.json
    skipped 79 lines
    80 80   "Physics",
    81 81   "Industrial and Materials Science"
    82 82   ]
     83 + },
     84 + {
     85 + "id": 3,
     86 + "location": null,
     87 + "location_country": null,
     88 + "staff": null,
     89 + "staff_first_name": null,
     90 + "departments": [
     91 + "nothing",
     92 + null
     93 + ]
    83 94   }
    84 95   ]
    85 96   }
    skipped 1 lines
  • ■ ■ ■ ■ ■ ■
    v3/crates/engine/tests/execute/remote_relationships/from_nested/expected.json
    skipped 32 lines
    33 33   }
    34 34   }
    35 35   ]
     36 + },
     37 + {
     38 + "staff": null
    36 39   }
    37 40   ]
    38 41   }
    skipped 32 lines
    71 74   }
    72 75   }
    73 76   ]
     77 + },
     78 + {
     79 + "staff": null
    74 80   }
    75 81   ]
    76 82   }
    skipped 32 lines
    109 115   }
    110 116   }
    111 117   ]
     118 + },
     119 + {
     120 + "staff": null
    112 121   }
    113 122   ]
    114 123   }
    skipped 32 lines
    147 156   }
    148 157   }
    149 158   ]
     159 + },
     160 + {
     161 + "staff": null
    150 162   }
    151 163   ]
    152 164   }
    skipped 2 lines
Please wait...
Page is in error, reload to recover