@@ -704,54 +704,57 @@ struct Transform {
704
704
}
705
705
706
706
impl Transform {
707
- fn variable ( & self , name : & str , pos : & Pos ) -> Result < r:: Value , QueryExecutionError > {
707
+ /// Look up the value of the variable `name`. If the variable is not
708
+ /// defined, return `r::Value::Null`
709
+ // graphql-bug-compat: Once queries are fully validated, all variables
710
+ // will be defined
711
+ fn variable ( & self , name : & str ) -> r:: Value {
708
712
self . variables
709
713
. get ( name)
710
714
. map ( |value| value. clone ( ) )
711
- . ok_or_else ( || QueryExecutionError :: MissingVariableError ( pos . clone ( ) , name . to_string ( ) ) )
715
+ . unwrap_or ( r :: Value :: Null )
712
716
}
713
717
714
718
/// Interpolate variable references in the arguments `args`
715
719
fn interpolate_arguments (
716
720
& self ,
717
721
args : Vec < ( String , q:: Value ) > ,
718
722
pos : & Pos ,
719
- ) -> Result < Vec < ( String , r:: Value ) > , QueryExecutionError > {
723
+ ) -> Vec < ( String , r:: Value ) > {
720
724
args. into_iter ( )
721
- . map ( |( name, val) | self . interpolate_value ( val, pos) . map ( |val| ( name, val) ) )
725
+ . map ( |( name, val) | {
726
+ let val = self . interpolate_value ( val, pos) ;
727
+ ( name, val)
728
+ } )
722
729
. collect ( )
723
730
}
724
731
725
732
/// Turn `value` into an `r::Value` by resolving variable references
726
- fn interpolate_value (
727
- & self ,
728
- value : q:: Value ,
729
- pos : & Pos ,
730
- ) -> Result < r:: Value , QueryExecutionError > {
733
+ fn interpolate_value ( & self , value : q:: Value , pos : & Pos ) -> r:: Value {
731
734
match value {
732
- q:: Value :: Variable ( var) => self . variable ( & var, pos ) ,
733
- q:: Value :: Int ( ref num) => Ok ( r :: Value :: Int (
734
- num. as_i64 ( ) . expect ( "q::Value::Int contains an i64" ) ,
735
- ) ) ,
736
- q:: Value :: Float ( f) => Ok ( r:: Value :: Float ( f) ) ,
737
- q:: Value :: String ( s) => Ok ( r:: Value :: String ( s) ) ,
738
- q:: Value :: Boolean ( b) => Ok ( r:: Value :: Boolean ( b) ) ,
739
- q:: Value :: Null => Ok ( r:: Value :: Null ) ,
740
- q:: Value :: Enum ( s) => Ok ( r:: Value :: Enum ( s) ) ,
735
+ q:: Value :: Variable ( var) => self . variable ( & var) ,
736
+ q:: Value :: Int ( ref num) => {
737
+ r :: Value :: Int ( num. as_i64 ( ) . expect ( "q::Value::Int contains an i64" ) )
738
+ }
739
+ q:: Value :: Float ( f) => r:: Value :: Float ( f) ,
740
+ q:: Value :: String ( s) => r:: Value :: String ( s) ,
741
+ q:: Value :: Boolean ( b) => r:: Value :: Boolean ( b) ,
742
+ q:: Value :: Null => r:: Value :: Null ,
743
+ q:: Value :: Enum ( s) => r:: Value :: Enum ( s) ,
741
744
q:: Value :: List ( vals) => {
742
- let vals: Vec < _ > = vals
745
+ let vals = vals
743
746
. into_iter ( )
744
747
. map ( |val| self . interpolate_value ( val, pos) )
745
- . collect :: < Result < Vec < _ > , _ > > ( ) ? ;
746
- Ok ( r:: Value :: List ( vals) )
748
+ . collect ( ) ;
749
+ r:: Value :: List ( vals)
747
750
}
748
751
q:: Value :: Object ( map) => {
749
752
let mut rmap = BTreeMap :: new ( ) ;
750
753
for ( key, value) in map. into_iter ( ) {
751
- let value = self . interpolate_value ( value, pos) ? ;
754
+ let value = self . interpolate_value ( value, pos) ;
752
755
rmap. insert ( key, value) ;
753
756
}
754
- Ok ( r:: Value :: object ( rmap) )
757
+ r:: Value :: object ( rmap)
755
758
}
756
759
}
757
760
}
@@ -763,22 +766,22 @@ impl Transform {
763
766
& self ,
764
767
dirs : Vec < q:: Directive > ,
765
768
) -> Result < ( Vec < a:: Directive > , bool ) , QueryExecutionError > {
766
- let dirs = dirs
769
+ let dirs: Vec < _ > = dirs
767
770
. into_iter ( )
768
771
. map ( |dir| {
769
772
let q:: Directive {
770
773
name,
771
774
position,
772
775
arguments,
773
776
} = dir;
774
- self . interpolate_arguments ( arguments, & position)
775
- . map ( |arguments| a:: Directive {
776
- name,
777
- position,
778
- arguments,
779
- } )
777
+ let arguments = self . interpolate_arguments ( arguments, & position) ;
778
+ a:: Directive {
779
+ name,
780
+ position,
781
+ arguments,
782
+ }
780
783
} )
781
- . collect :: < Result < Vec < _ > , _ > > ( ) ? ;
784
+ . collect ( ) ;
782
785
let skip = dirs. iter ( ) . any ( |dir| dir. skip ( ) ) ;
783
786
Ok ( ( dirs, skip) )
784
787
}
@@ -887,7 +890,7 @@ impl Transform {
887
890
return Ok ( None ) ;
888
891
}
889
892
890
- let mut arguments = self . interpolate_arguments ( arguments, & position) ? ;
893
+ let mut arguments = self . interpolate_arguments ( arguments, & position) ;
891
894
self . coerce_argument_values ( & mut arguments, parent_type, & name) ?;
892
895
893
896
let is_leaf_type = self . schema . document ( ) . is_leaf_type ( & field_type. field_type ) ;
0 commit comments