@@ -45,7 +45,7 @@ pub fn project_by_operation(
4545 & mut errors,
4646 selections,
4747 variable_values,
48- operation_type_name,
48+ Some ( operation_type_name) ,
4949 & mut buffer,
5050 & mut first,
5151 ) ;
@@ -153,9 +153,8 @@ fn project_selection_set(
153153 selections : Some ( selections) ,
154154 } => {
155155 let mut first = true ;
156- let type_name = get_value_by_key ( obj, TYPENAME_FIELD_NAME )
157- . and_then ( |v| v. as_str ( ) )
158- . unwrap_or ( selection. field_type . as_str ( ) ) ;
156+ let type_name =
157+ get_value_by_key ( obj, TYPENAME_FIELD_NAME ) . and_then ( |v| v. as_str ( ) ) ;
159158 project_selection_set_with_map (
160159 obj,
161160 errors,
@@ -193,7 +192,7 @@ fn project_selection_set(
193192fn project_field (
194193 field_val : Option < & Value > ,
195194 plan : & FieldProjectionPlan ,
196- parent_type_name : & str ,
195+ parent_type_name : Option < & str > ,
197196 variable_values : & Option < HashMap < String , sonic_rs:: Value > > ,
198197 buffer : & mut Vec < u8 > ,
199198 first : & mut bool ,
@@ -280,10 +279,14 @@ fn project_field(
280279 if let Some ( field_val) = field_val {
281280 project_selection_set ( field_val, errors, plan, variable_values, buffer) ;
282281 } else if plan. field_name == TYPENAME_FIELD_NAME {
283- // If the field is TYPENAME_FIELD, we should set it to the parent type name
284- buffer. put ( QUOTE ) ;
285- buffer. put ( parent_type_name. as_bytes ( ) ) ;
286- buffer. put ( QUOTE ) ;
282+ if let Some ( parent_type_name) = parent_type_name {
283+ // If the field is TYPENAME_FIELD, we should set it to the parent type name
284+ buffer. put ( QUOTE ) ;
285+ buffer. put ( parent_type_name. as_bytes ( ) ) ;
286+ buffer. put ( QUOTE ) ;
287+ } else {
288+ buffer. put ( NULL ) ;
289+ }
287290 } else {
288291 // If the field is not found in the object, set it to Null
289292 buffer. put ( NULL ) ;
@@ -379,7 +382,7 @@ fn project_selection_set_with_map(
379382 errors : & mut Vec < GraphQLError > ,
380383 plans : & IndexMap < String , FieldProjectionPlan > ,
381384 variable_values : & Option < HashMap < String , sonic_rs:: Value > > ,
382- parent_type_name : & str ,
385+ parent_type_name : Option < & str > ,
383386 buffer : & mut Vec < u8 > ,
384387 first : & mut bool ,
385388) {
@@ -400,7 +403,7 @@ fn project_selection_set_with_map(
400403
401404fn check < ' a > (
402405 cond : & ' a FieldProjectionCondition ,
403- parent_type_name : & ' a str ,
406+ parent_type_name : Option < & ' a str > ,
404407 field_type_name : Option < & ' a str > ,
405408 field_value : Option < & ' a Value > ,
406409 variable_values : & ' a Option < HashMap < String , sonic_rs:: Value > > ,
@@ -464,18 +467,21 @@ fn check<'a>(
464467 Ok ( ( ) )
465468 }
466469 FieldProjectionCondition :: ParentTypeCondition ( type_condition) => {
467- let is_valid = match type_condition {
468- TypeCondition :: Exact ( expected_type) => parent_type_name == expected_type,
469- TypeCondition :: OneOf ( possible_types) => possible_types. contains ( parent_type_name) ,
470- } ;
471- if is_valid {
472- Ok ( ( ) )
473- } else {
474- Err ( FieldProjectionConditionError :: InvalidParentType {
475- expected : type_condition,
476- found : parent_type_name,
477- } )
470+ if let Some ( parent_type_name) = parent_type_name {
471+ let is_valid = match type_condition {
472+ TypeCondition :: Exact ( expected_type) => parent_type_name == expected_type,
473+ TypeCondition :: OneOf ( possible_types) => {
474+ possible_types. contains ( parent_type_name)
475+ }
476+ } ;
477+ if !is_valid {
478+ return Err ( FieldProjectionConditionError :: InvalidParentType {
479+ expected : type_condition,
480+ found : parent_type_name,
481+ } ) ;
482+ }
478483 }
484+ Ok ( ( ) )
479485 }
480486 FieldProjectionCondition :: FieldTypeCondition ( type_condition) => {
481487 if let Some ( field_type_name) = field_type_name {
0 commit comments