@@ -12,21 +12,35 @@ open FSharp.Data.GraphQL.Ast
12
12
13
13
let internal removeNoFilter = Seq.where ( fun filter -> filter <> NoFilter)
14
14
15
+ type private ComparisonOperator =
16
+ | EndsWith of string
17
+ | StartsWith of string
18
+ | Contains of string
19
+ | Equals of string
20
+ | GreaterThan of string
21
+ | GreaterThanOrEqual of string
22
+ | LessThan of string
23
+ | LessThanOrEqual of string
24
+
15
25
let rec private coerceObjectListFilterInput x : Result < ObjectListFilter , IGQLError list > =
16
26
17
- let (| EndsWith | StartsWith | GreaterThan | LessThan | Contains | Equals |) ( s : string ) =
27
+ let parseFieldCondition ( s : string ) =
18
28
let s = s.ToLowerInvariant ()
19
29
let prefix ( suffix : string ) ( s : string ) = s.Substring ( 0 , s.Length - suffix.Length)
20
30
match s with
21
31
| s when s.EndsWith ( " _ends_with" ) && s.Length > " _ends_with" .Length -> EndsWith ( prefix " _ends_with" s)
22
32
| s when s.EndsWith ( " _ew" ) && s.Length > " _ew" .Length -> EndsWith ( prefix " _ew" s)
23
33
| s when s.EndsWith ( " _starts_with" ) && s.Length > " _starts_with" .Length -> StartsWith ( prefix " _starts_with" s)
24
34
| s when s.EndsWith ( " _sw" ) && s.Length > " _sw" .Length -> StartsWith ( prefix " _sw" s)
35
+ | s when s.EndsWith ( " _contains" ) && s.Length > " _contains" .Length -> Contains ( prefix " _contains" s)
25
36
| s when s.EndsWith ( " _greater_than" ) && s.Length > " _greater_than" .Length -> GreaterThan ( prefix " _greater_than" s)
26
37
| s when s.EndsWith ( " _gt" ) && s.Length > " _gt" .Length -> GreaterThan ( prefix " _gt" s)
38
+ | s when s.EndsWith ( " _greater_than_or_equal" ) && s.Length > " _greater_than_or_equal" .Length -> GreaterThanOrEqual ( prefix " _greater_than_or_equal" s)
39
+ | s when s.EndsWith ( " _gte" ) && s.Length > " _gte" .Length -> GreaterThanOrEqual ( prefix " _gte" s)
27
40
| s when s.EndsWith ( " _less_than" ) && s.Length > " _less_than" .Length -> LessThan ( prefix " _less_than" s)
28
41
| s when s.EndsWith ( " _lt" ) && s.Length > " _lt" .Length -> LessThan ( prefix " _lt" s)
29
- | s when s.EndsWith ( " _contains" ) && s.Length > " _contains" .Length -> Contains ( prefix " _contains" s)
42
+ | s when s.EndsWith ( " _less_than_or_equal" ) && s.Length > " _less_than_or_equal" .Length -> LessThanOrEqual ( prefix " _less_than_or_equal" s)
43
+ | s when s.EndsWith ( " _lte" ) && s.Length > " _lte" .Length -> LessThanOrEqual ( prefix " _lte" s)
30
44
| s -> Equals s
31
45
32
46
let (| EquatableValue | Other |) v =
@@ -76,25 +90,27 @@ let rec private coerceObjectListFilterInput x : Result<ObjectListFilter, IGQLErr
76
90
match coerceResults with
77
91
| Error errs -> Error errs
78
92
| Ok coerced -> coerced |> removeNoFilter |> Seq.toList |> Ok
79
- match name, value with
93
+ match parseFieldCondition name, value with
80
94
| Equals " and" , ListValue fields -> fields |> mapFilters |> Result.map buildAnd
81
95
| Equals " or" , ListValue fields -> fields |> mapFilters |> Result.map buildOr
82
96
| Equals " not" , ObjectValue value ->
83
97
match mapInput value with
84
98
| Error errs -> Error errs
85
99
| Ok NoFilter -> Ok NoFilter
86
100
| Ok filter -> Ok ( Not filter)
87
- | EndsWith fname, StringValue value -> Ok ( EndsWith { FieldName = fname; Value = value })
88
- | StartsWith fname, StringValue value -> Ok ( StartsWith { FieldName = fname; Value = value })
89
- | Contains fname, StringValue value -> Ok ( Contains { FieldName = fname; Value = value })
101
+ | EndsWith fname, StringValue value -> Ok ( ObjectListFilter. EndsWith { FieldName = fname; Value = value })
102
+ | StartsWith fname, StringValue value -> Ok ( ObjectListFilter. StartsWith { FieldName = fname; Value = value })
103
+ | Contains fname, StringValue value -> Ok ( ObjectListFilter. Contains { FieldName = fname; Value = value })
90
104
| Equals fname, ObjectValue value ->
91
105
match mapInput value with
92
106
| Error errs -> Error errs
93
107
| Ok NoFilter -> Ok NoFilter
94
108
| Ok filter -> Ok ( FilterField { FieldName = fname; Value = filter })
95
- | Equals fname, EquatableValue value -> Ok ( Equals { FieldName = fname; Value = value })
96
- | GreaterThan fname, ComparableValue value -> Ok ( GreaterThan { FieldName = fname; Value = value })
97
- | LessThan fname, ComparableValue value -> Ok ( LessThan { FieldName = fname; Value = value })
109
+ | Equals fname, EquatableValue value -> Ok ( ObjectListFilter.Equals { FieldName = fname; Value = value })
110
+ | GreaterThan fname, ComparableValue value -> Ok ( ObjectListFilter.GreaterThan { FieldName = fname; Value = value })
111
+ | GreaterThanOrEqual fname, ComparableValue value -> Ok ( ObjectListFilter.GreaterThanOrEqual { FieldName = fname; Value = value })
112
+ | LessThan fname, ComparableValue value -> Ok ( ObjectListFilter.LessThan { FieldName = fname; Value = value })
113
+ | LessThanOrEqual fname, ComparableValue value -> Ok ( ObjectListFilter.LessThanOrEqual { FieldName = fname; Value = value })
98
114
| _ -> Ok NoFilter
99
115
100
116
and mapInput value =
0 commit comments