@@ -15,6 +15,7 @@ local avro_helpers = require('graphql.avro_helpers')
15
15
local db_schema_helpers = require (' graphql.db_schema_helpers' )
16
16
local error_codes = require (' graphql.error_codes' )
17
17
local statistics = require (' graphql.statistics' )
18
+ local expressions = require (' graphql.expressions' )
18
19
19
20
local check = utils .check
20
21
local e = error_codes
@@ -763,7 +764,7 @@ local function validate_collections(collections, schemas)
763
764
end
764
765
end
765
766
766
- --- Whether an object match set of PCRE .
767
+ --- Whether an object match set of PCREs .
767
768
---
768
769
--- @tparam table obj an object to check
769
770
---
@@ -817,6 +818,28 @@ local function match_using_re(obj, pcre)
817
818
return true
818
819
end
819
820
821
+ --- Whether an object match an expression.
822
+ ---
823
+ --- @tparam table obj an object to check
824
+ ---
825
+ --- @param expr (table or string ) compiled or raw expression
826
+ ---
827
+ --- @tparam [opt] table variables variables values from the request
828
+ ---
829
+ --- @treturn boolean `res` whether the `obj` object match `expr` expression
830
+ local function match_using_expr (obj , expr , variables )
831
+ if expr == nil then return true end
832
+
833
+ -- XXX: compile it outside of process_tuple
834
+ if type (expr ) == ' string' then
835
+ expr = expressions .new (expr )
836
+ end
837
+ check (expr , ' expression' , ' table' )
838
+ local res = expr :execute (obj , variables )
839
+ check (res , ' expression result' , ' boolean' )
840
+ return res
841
+ end
842
+
820
843
--- Check whether we meet deadline time.
821
844
---
822
845
--- The functions raises an exception in the case.
857
880
--- * `pivot_filter` (table, set of fields to match the objected pointed by
858
881
--- `offset` arqument of the GraphQL query),
859
882
--- * `resolveField` (function) for subrequests, see @{impl.new}.
883
+ --- * XXX: describe other fields.
860
884
---
861
885
--- @return nil
862
886
---
@@ -887,7 +911,9 @@ local function process_tuple(self, state, tuple, opts)
887
911
888
912
local collection_name = opts .collection_name
889
913
local pcre = opts .pcre
914
+ local expr = opts .expr
890
915
local resolveField = opts .resolveField
916
+ local variables = qcontext .variables
891
917
892
918
-- convert tuple -> object
893
919
local obj = opts .unflatten_tuple (self , collection_name , tuple ,
@@ -918,7 +944,7 @@ local function process_tuple(self, state, tuple, opts)
918
944
919
945
-- filter out non-matching objects
920
946
local match = utils .is_subtable (obj , truncated_filter ) and
921
- match_using_re (obj , pcre )
947
+ match_using_re (obj , pcre ) and match_using_expr ( obj , expr , variables )
922
948
if do_filter then
923
949
if not match then return true end
924
950
else
@@ -1069,6 +1095,7 @@ local function prepare_select_internal(self, collection_name, from, filter,
1069
1095
use_tomap = self .collection_use_tomap [collection_name ] or false ,
1070
1096
default_unflatten_tuple = default_unflatten_tuple ,
1071
1097
pcre = args .pcre ,
1098
+ expr = args .filter ,
1072
1099
resolveField = extra .resolveField ,
1073
1100
is_hidden = extra .is_hidden ,
1074
1101
}
0 commit comments