@@ -741,17 +741,17 @@ struct Transform {
741
741
}
742
742
743
743
impl Transform {
744
- fn variable (
745
- & self ,
746
- name : & str ,
747
- default : Option < r :: Value > ,
748
- pos : & Pos ,
749
- ) -> Result < r:: Value , QueryExecutionError > {
744
+ /// Look up the value of the variable `name`. If the variable is not
745
+ /// defined, return `r::Value::Null`
746
+ // graphql-bug-compat: use `default` as the value for an undefined
747
+ // variable. Once queries are fully validated, all variables will be
748
+ // defined
749
+ fn variable ( & self , name : & str , default : Option < r:: Value > ) -> r :: Value {
750
750
self . variables
751
751
. get ( name)
752
752
. map ( |value| value. clone ( ) )
753
753
. or ( default)
754
- . ok_or_else ( || QueryExecutionError :: MissingVariableError ( pos . clone ( ) , name . to_string ( ) ) )
754
+ . unwrap_or ( r :: Value :: Null )
755
755
}
756
756
757
757
/// Interpolate variable references in the arguments `args`
@@ -760,47 +760,42 @@ impl Transform {
760
760
args : Vec < ( String , q:: Value ) > ,
761
761
defaults : & dyn DefaultLookup ,
762
762
pos : & Pos ,
763
- ) -> Result < Vec < ( String , r:: Value ) > , QueryExecutionError > {
763
+ ) -> Vec < ( String , r:: Value ) > {
764
764
args. into_iter ( )
765
765
. map ( |( name, val) | {
766
766
let default = defaults. find ( & name) ;
767
- self . interpolate_value ( val, default, pos)
768
- . map ( |val| ( name, val) )
767
+ let val = self . interpolate_value ( val, default, pos) ;
768
+ ( name, val)
769
769
} )
770
770
. collect ( )
771
771
}
772
772
773
773
/// Turn `value` into an `r::Value` by resolving variable references
774
- fn interpolate_value (
775
- & self ,
776
- value : q:: Value ,
777
- default : Option < r:: Value > ,
778
- pos : & Pos ,
779
- ) -> Result < r:: Value , QueryExecutionError > {
774
+ fn interpolate_value ( & self , value : q:: Value , default : Option < r:: Value > , pos : & Pos ) -> r:: Value {
780
775
match value {
781
- q:: Value :: Variable ( var) => self . variable ( & var, default, pos ) ,
782
- q:: Value :: Int ( ref num) => Ok ( r :: Value :: Int (
783
- num. as_i64 ( ) . expect ( "q::Value::Int contains an i64" ) ,
784
- ) ) ,
785
- q:: Value :: Float ( f) => Ok ( r:: Value :: Float ( f) ) ,
786
- q:: Value :: String ( s) => Ok ( r:: Value :: String ( s) ) ,
787
- q:: Value :: Boolean ( b) => Ok ( r:: Value :: Boolean ( b) ) ,
788
- q:: Value :: Null => Ok ( r:: Value :: Null ) ,
789
- q:: Value :: Enum ( s) => Ok ( r:: Value :: Enum ( s) ) ,
776
+ q:: Value :: Variable ( var) => self . variable ( & var, default) ,
777
+ q:: Value :: Int ( ref num) => {
778
+ r :: Value :: Int ( num. as_i64 ( ) . expect ( "q::Value::Int contains an i64" ) )
779
+ }
780
+ q:: Value :: Float ( f) => r:: Value :: Float ( f) ,
781
+ q:: Value :: String ( s) => r:: Value :: String ( s) ,
782
+ q:: Value :: Boolean ( b) => r:: Value :: Boolean ( b) ,
783
+ q:: Value :: Null => r:: Value :: Null ,
784
+ q:: Value :: Enum ( s) => r:: Value :: Enum ( s) ,
790
785
q:: Value :: List ( vals) => {
791
- let vals: Vec < _ > = vals
786
+ let vals = vals
792
787
. into_iter ( )
793
788
. map ( |val| self . interpolate_value ( val, None , pos) )
794
- . collect :: < Result < Vec < _ > , _ > > ( ) ? ;
795
- Ok ( r:: Value :: List ( vals) )
789
+ . collect ( ) ;
790
+ r:: Value :: List ( vals)
796
791
}
797
792
q:: Value :: Object ( map) => {
798
793
let mut rmap = BTreeMap :: new ( ) ;
799
794
for ( key, value) in map. into_iter ( ) {
800
- let value = self . interpolate_value ( value, None , pos) ? ;
795
+ let value = self . interpolate_value ( value, None , pos) ;
801
796
rmap. insert ( key, value) ;
802
797
}
803
- Ok ( r:: Value :: object ( rmap) )
798
+ r:: Value :: object ( rmap)
804
799
}
805
800
}
806
801
}
@@ -813,7 +808,7 @@ impl Transform {
813
808
dirs : Vec < q:: Directive > ,
814
809
defns : & Vec < s:: Directive > ,
815
810
) -> Result < ( Vec < a:: Directive > , bool ) , QueryExecutionError > {
816
- let dirs = dirs
811
+ let dirs: Vec < _ > = dirs
817
812
. into_iter ( )
818
813
. map ( |dir| {
819
814
let q:: Directive {
@@ -827,14 +822,14 @@ impl Transform {
827
822
. find ( |defn| defn. name == name)
828
823
. map ( |defn| & defn. arguments ) ,
829
824
) ;
830
- self . interpolate_arguments ( arguments, & defaults, & position)
831
- . map ( |arguments| a:: Directive {
832
- name,
833
- position,
834
- arguments,
835
- } )
825
+ let arguments = self . interpolate_arguments ( arguments, & defaults, & position) ;
826
+ a:: Directive {
827
+ name,
828
+ position,
829
+ arguments,
830
+ }
836
831
} )
837
- . collect :: < Result < Vec < _ > , _ > > ( ) ? ;
832
+ . collect ( ) ;
838
833
let skip = dirs. iter ( ) . any ( |dir| dir. skip ( ) ) ;
839
834
Ok ( ( dirs, skip) )
840
835
}
@@ -944,7 +939,7 @@ impl Transform {
944
939
}
945
940
946
941
let mut arguments =
947
- self . interpolate_arguments ( arguments, & FieldArgumentDefaults ( & field_type) , & position) ? ;
942
+ self . interpolate_arguments ( arguments, & FieldArgumentDefaults ( & field_type) , & position) ;
948
943
self . coerce_argument_values ( & mut arguments, parent_type, & name) ?;
949
944
950
945
let is_leaf_type = self . schema . document ( ) . is_leaf_type ( & field_type. field_type ) ;
0 commit comments