@@ -9,6 +9,7 @@ open System.Text.Json
9
9
open FSharp.Data .GraphQL
10
10
open FSharp.Data .GraphQL .Types
11
11
open FSharp.Data .GraphQL .Ast
12
+ open FsToolkit.ErrorHandling
12
13
13
14
type private ComparisonOperator =
14
15
| EndsWith of string
@@ -19,6 +20,7 @@ type private ComparisonOperator =
19
20
| GreaterThanOrEqual of string
20
21
| LessThan of string
21
22
| LessThanOrEqual of string
23
+ | In of string
22
24
23
25
let rec private coerceObjectListFilterInput x : Result < ObjectListFilter voption , IGQLError list > =
24
26
@@ -39,24 +41,25 @@ let rec private coerceObjectListFilterInput x : Result<ObjectListFilter voption,
39
41
| s when s.EndsWith ( " _lt" ) && s.Length > " _lt" .Length -> LessThan ( prefix " _lt" s)
40
42
| s when s.EndsWith ( " _less_than_or_equal" ) && s.Length > " _less_than_or_equal" .Length -> LessThanOrEqual ( prefix " _less_than_or_equal" s)
41
43
| s when s.EndsWith ( " _lte" ) && s.Length > " _lte" .Length -> LessThanOrEqual ( prefix " _lte" s)
44
+ | s when s.EndsWith ( " _in" ) && s.Length > " _in" .Length -> In ( prefix " _in" s)
42
45
| s -> Equals s
43
46
44
- let (| EquatableValue | Other |) v =
47
+ let (| EquatableValue | NonEquatableValue |) v =
45
48
match v with
46
49
| IntValue v -> EquatableValue ( v :> System.IComparable)
47
50
| FloatValue v -> EquatableValue ( v :> System.IComparable)
48
51
| BooleanValue v -> EquatableValue ( v :> System.IComparable)
49
52
| StringValue v -> EquatableValue ( v :> System.IComparable)
50
53
| EnumValue v -> EquatableValue ( v :> System.IComparable)
51
- | v -> Other v
54
+ | v -> NonEquatableValue v
52
55
53
- let (| ComparableValue | Other |) v =
56
+ let (| ComparableValue | NonComparableValue |) v =
54
57
match v with
55
58
| IntValue v -> ComparableValue ( v :> System.IComparable)
56
59
| FloatValue v -> ComparableValue ( v :> System.IComparable)
57
60
| BooleanValue v -> ComparableValue ( v :> System.IComparable)
58
61
| StringValue v -> ComparableValue ( v :> System.IComparable)
59
- | v -> Other v
62
+ | v -> NonComparableValue v
60
63
61
64
let buildAnd x =
62
65
let rec build acc x =
@@ -98,7 +101,7 @@ let rec private coerceObjectListFilterInput x : Result<ObjectListFilter voption,
98
101
| Ok ( ValueSome filter) -> Ok ( ValueSome ( Not filter))
99
102
| EndsWith fname, StringValue value -> Ok ( ValueSome ( ObjectListFilter.EndsWith { FieldName = fname; Value = value }))
100
103
| StartsWith fname, StringValue value -> Ok ( ValueSome ( ObjectListFilter.StartsWith { FieldName = fname; Value = value }))
101
- | Contains fname, StringValue value -> Ok ( ValueSome ( ObjectListFilter.Contains { FieldName = fname; Value = value }))
104
+ | Contains fname, ComparableValue value -> Ok ( ValueSome ( ObjectListFilter.Contains { FieldName = fname; Value = value }))
102
105
| Equals fname, ObjectValue value ->
103
106
match mapInput value with
104
107
| Error errs -> Error errs
@@ -109,6 +112,20 @@ let rec private coerceObjectListFilterInput x : Result<ObjectListFilter voption,
109
112
| GreaterThanOrEqual fname, ComparableValue value -> Ok ( ValueSome ( ObjectListFilter.GreaterThanOrEqual { FieldName = fname; Value = value }))
110
113
| LessThan fname, ComparableValue value -> Ok ( ValueSome ( ObjectListFilter.LessThan { FieldName = fname; Value = value }))
111
114
| LessThanOrEqual fname, ComparableValue value -> Ok ( ValueSome ( ObjectListFilter.LessThanOrEqual { FieldName = fname; Value = value }))
115
+ | In fname, ListValue values -> result {
116
+ let! parsedValues =
117
+ values
118
+ |> Seq.map ( function
119
+ | EquatableValue v -> Ok v
120
+ | NonEquatableValue v ->
121
+ Error
122
+ { new IGQLError with
123
+ member _.Message = $" Cannot coerce '{v.GetType ()}' to 'System.IComparable'"
124
+ })
125
+ |> Seq.toList
126
+ |> splitSeqErrors
127
+ return ValueSome ( ObjectListFilter.In { FieldName = fname; Value = parsedValues |> Array.toList })
128
+ }
112
129
| _ -> Ok ValueNone
113
130
114
131
and mapInput value =
@@ -172,7 +189,13 @@ let ObjectListFilterType : ScalarDefinition<ObjectListFilter> = {
172
189
" The `Filter` scalar type represents a filter on one or more fields of an object in an object list. The filter is represented by a JSON object where the fields are the complemented by specific suffixes to represent a query."
173
190
CoerceInput =
174
191
( function
175
- | InlineConstant c -> coerceObjectListFilterInput c |> Result.map ValueOption.toObj
176
- | Variable json -> json |> jsonElementToInputValue |> coerceObjectListFilterInput |> Result.map ValueOption.toObj)
192
+ | InlineConstant c ->
193
+ coerceObjectListFilterInput c
194
+ |> Result.map ValueOption.toObj
195
+ | Variable json ->
196
+ json
197
+ |> jsonElementToInputValue
198
+ |> coerceObjectListFilterInput
199
+ |> Result.map ValueOption.toObj)
177
200
CoerceOutput = coerceObjectListFilterValue
178
201
}
0 commit comments