Skip to content

Commit 9585b19

Browse files
Copilotxperiandri
andauthored
Extract filter suffix constants to FilterSuffixConstants.fs
Co-authored-by: xperiandri <2365592+xperiandri@users.noreply.github.com>
1 parent 9fa9659 commit 9585b19

3 files changed

Lines changed: 91 additions & 94 deletions

File tree

src/FSharp.Data.GraphQL.Server.Middleware/FSharp.Data.GraphQL.Server.Middleware.fsproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121

2222
<ItemGroup>
2323
<Compile Include="ObjectListFilter.fs" />
24+
<Compile Include="FilterSuffixConstants.fs" />
2425
<Compile Include="TypeSystemExtensions.fs" />
2526
<Compile Include="SchemaDefinitions.fs" />
2627
<Compile Include="MiddlewareDefinitions.fs" />
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
/// <summary>
2+
/// String filter suffixes:
3+
/// lowercase (e.g. _ends_with, _ew) → case-insensitive (OrdinalIgnoreCase)
4+
/// Capitalized (e.g. _Ends_With, _EW) → case-sensitive (Ordinal)
5+
/// <para>
6+
/// The <see cref="CI"/> submodule contains lowercase suffixes that map to case-insensitive string comparisons.
7+
/// The <see cref="CS"/> submodule contains capitalized/uppercase suffixes that map to case-sensitive string comparisons.
8+
/// Numeric and comparison operator suffixes are defined at the module level and are case-insensitive by convention.
9+
/// </para>
10+
/// </summary>
11+
[<RequireQualifiedAccess>]
12+
module FSharp.Data.GraphQL.Server.Middleware.FilterSuffixConstants
13+
14+
// Numeric/comparison operators
15+
[<Literal>]
16+
let GreaterThanOrEqualSuffix = "_greater_than_or_equal"
17+
[<Literal>]
18+
let GTESuffix = "_gte"
19+
[<Literal>]
20+
let GreaterThanSuffix = "_greater_than"
21+
[<Literal>]
22+
let GTSuffix = "_gt"
23+
[<Literal>]
24+
let LessThanOrEqualSuffix = "_less_than_or_equal"
25+
[<Literal>]
26+
let LTESuffix = "_lte"
27+
[<Literal>]
28+
let LessThanSuffix = "_less_than"
29+
[<Literal>]
30+
let LTSuffix = "_lt"
31+
[<Literal>]
32+
let InSuffix = "_in"
33+
34+
/// Case-insensitive string operators (lowercase suffixes → OrdinalIgnoreCase)
35+
module CI =
36+
// String operators (case-insensitive)
37+
[<Literal>]
38+
let EndsWithSuffix = "_ends_with"
39+
[<Literal>]
40+
let EWSuffix = "_ew"
41+
[<Literal>]
42+
let StartsWithSuffix = "_starts_with"
43+
[<Literal>]
44+
let SWSuffix = "_sw"
45+
[<Literal>]
46+
let ContainsSuffix = "_contains"
47+
[<Literal>]
48+
let EqualsSuffix = "_equals"
49+
[<Literal>]
50+
let EQSuffix = "_eq"
51+
52+
/// Case-sensitive string operators
53+
module CS =
54+
[<Literal>]
55+
let EndsWithSuffix = "_Ends_With"
56+
[<Literal>]
57+
let EWSuffix = "_EW"
58+
[<Literal>]
59+
let StartsWithSuffix = "_Starts_With"
60+
[<Literal>]
61+
let SWSuffix = "_SW"
62+
[<Literal>]
63+
let ContainsSuffix = "_Contains"
64+
[<Literal>]
65+
let EqualsSuffix = "_Equals"
66+
[<Literal>]
67+
let EQSuffix = "_EQ"

src/FSharp.Data.GraphQL.Server.Middleware/SchemaDefinitions.fs

Lines changed: 23 additions & 94 deletions
Original file line numberDiff line numberDiff line change
@@ -20,111 +20,40 @@ type private ComparisonOperator =
2020
| LessThanOrEqual of string
2121
| In of string
2222

23-
// String filter suffixes:
24-
// lowercase (e.g. _ends_with, _ew) → case-insensitive (OrdinalIgnoreCase)
25-
// Capitalized (e.g. _Ends_With, _EW) → case-sensitive (Ordinal)
26-
[<Literal>]
27-
let private endsWithSuffix = "_ends_with"
28-
29-
[<Literal>]
30-
let private ewSuffix = "_ew"
31-
32-
[<Literal>]
33-
let private EndsWithCSSuffix = "_Ends_With"
34-
35-
[<Literal>]
36-
let private EWCSSuffix = "_EW"
37-
38-
[<Literal>]
39-
let private startsWithSuffix = "_starts_with"
40-
41-
[<Literal>]
42-
let private swSuffix = "_sw"
43-
44-
[<Literal>]
45-
let private StartsWithCSSuffix = "_Starts_With"
46-
47-
[<Literal>]
48-
let private SWCSSuffix = "_SW"
49-
50-
[<Literal>]
51-
let private containsSuffix = "_contains"
52-
53-
[<Literal>]
54-
let private ContainsCSSuffix = "_Contains"
55-
56-
[<Literal>]
57-
let private equalsSuffix = "_equals"
58-
59-
[<Literal>]
60-
let private eqSuffix = "_eq"
61-
62-
[<Literal>]
63-
let private EqualsCSSuffix = "_Equals"
64-
65-
[<Literal>]
66-
let private EQCSSuffix = "_EQ"
67-
68-
[<Literal>]
69-
let private greaterThanOrEqualSuffix = "_greater_than_or_equal"
70-
71-
[<Literal>]
72-
let private gteSuffix = "_gte"
73-
74-
[<Literal>]
75-
let private greaterThanSuffix = "_greater_than"
76-
77-
[<Literal>]
78-
let private gtSuffix = "_gt"
79-
80-
[<Literal>]
81-
let private lessThanOrEqualSuffix = "_less_than_or_equal"
82-
83-
[<Literal>]
84-
let private lteSuffix = "_lte"
85-
86-
[<Literal>]
87-
let private lessThanSuffix = "_less_than"
88-
89-
[<Literal>]
90-
let private ltSuffix = "_lt"
91-
92-
[<Literal>]
93-
let private inSuffix = "_in"
9423

9524
let rec private coerceObjectListFilterInput (variables : Variables) inputValue : Result<ObjectListFilter voption, IGQLError list> =
9625

9726
let parseFieldCondition (s : string) =
9827
let prefix (suffix : string) (s : string) = s.Substring (0, s.Length - suffix.Length)
9928
// Phase 1: case-sensitive string ops – match original string against capitalized/uppercase suffixes
10029
match s with
101-
| s when s.EndsWith EndsWithCSSuffix && s.Length > EndsWithCSSuffix.Length -> EndsWith (prefix EndsWithCSSuffix s, StringComparer.Ordinal)
102-
| s when s.EndsWith EWCSSuffix && s.Length > EWCSSuffix.Length -> EndsWith (prefix EWCSSuffix s, StringComparer.Ordinal)
103-
| s when s.EndsWith StartsWithCSSuffix && s.Length > StartsWithCSSuffix.Length -> StartsWith (prefix StartsWithCSSuffix s, StringComparer.Ordinal)
104-
| s when s.EndsWith SWCSSuffix && s.Length > SWCSSuffix.Length -> StartsWith (prefix SWCSSuffix s, StringComparer.Ordinal)
105-
| s when s.EndsWith ContainsCSSuffix && s.Length > ContainsCSSuffix.Length -> Contains (prefix ContainsCSSuffix s, StringComparer.Ordinal)
106-
| s when s.EndsWith EqualsCSSuffix && s.Length > EqualsCSSuffix.Length -> StringEquals (prefix EqualsCSSuffix s, StringComparer.Ordinal)
107-
| s when s.EndsWith EQCSSuffix && s.Length > EQCSSuffix.Length -> StringEquals (prefix EQCSSuffix s, StringComparer.Ordinal)
30+
| s when s.EndsWith FilterSuffixConstants.CS.EndsWithSuffix && s.Length > FilterSuffixConstants.CS.EndsWithSuffix.Length -> EndsWith (prefix FilterSuffixConstants.CS.EndsWithSuffix s, StringComparer.Ordinal)
31+
| s when s.EndsWith FilterSuffixConstants.CS.EWSuffix && s.Length > FilterSuffixConstants.CS.EWSuffix.Length -> EndsWith (prefix FilterSuffixConstants.CS.EWSuffix s, StringComparer.Ordinal)
32+
| s when s.EndsWith FilterSuffixConstants.CS.StartsWithSuffix && s.Length > FilterSuffixConstants.CS.StartsWithSuffix.Length -> StartsWith (prefix FilterSuffixConstants.CS.StartsWithSuffix s, StringComparer.Ordinal)
33+
| s when s.EndsWith FilterSuffixConstants.CS.SWSuffix && s.Length > FilterSuffixConstants.CS.SWSuffix.Length -> StartsWith (prefix FilterSuffixConstants.CS.SWSuffix s, StringComparer.Ordinal)
34+
| s when s.EndsWith FilterSuffixConstants.CS.ContainsSuffix && s.Length > FilterSuffixConstants.CS.ContainsSuffix.Length -> Contains (prefix FilterSuffixConstants.CS.ContainsSuffix s, StringComparer.Ordinal)
35+
| s when s.EndsWith FilterSuffixConstants.CS.EqualsSuffix && s.Length > FilterSuffixConstants.CS.EqualsSuffix.Length -> StringEquals (prefix FilterSuffixConstants.CS.EqualsSuffix s, StringComparer.Ordinal)
36+
| s when s.EndsWith FilterSuffixConstants.CS.EQSuffix && s.Length > FilterSuffixConstants.CS.EQSuffix.Length -> StringEquals (prefix FilterSuffixConstants.CS.EQSuffix s, StringComparer.Ordinal)
10837
| _ ->
10938
// Phase 2: case-insensitive string ops and numeric ops – lower-case before matching
11039
let s = s.ToLowerInvariant ()
11140
match s with
112-
| s when s.EndsWith endsWithSuffix && s.Length > endsWithSuffix.Length -> EndsWith (prefix endsWithSuffix s, StringComparer.OrdinalIgnoreCase)
113-
| s when s.EndsWith ewSuffix && s.Length > ewSuffix.Length -> EndsWith (prefix ewSuffix s, StringComparer.OrdinalIgnoreCase)
114-
| s when s.EndsWith startsWithSuffix && s.Length > startsWithSuffix.Length -> StartsWith (prefix startsWithSuffix s, StringComparer.OrdinalIgnoreCase)
115-
| s when s.EndsWith swSuffix && s.Length > swSuffix.Length -> StartsWith (prefix swSuffix s, StringComparer.OrdinalIgnoreCase)
116-
| s when s.EndsWith containsSuffix && s.Length > containsSuffix.Length -> Contains (prefix containsSuffix s, StringComparer.OrdinalIgnoreCase)
117-
| s when s.EndsWith equalsSuffix && s.Length > equalsSuffix.Length -> StringEquals (prefix equalsSuffix s, StringComparer.OrdinalIgnoreCase)
118-
| s when s.EndsWith eqSuffix && s.Length > eqSuffix.Length -> StringEquals (prefix eqSuffix s, StringComparer.OrdinalIgnoreCase)
119-
| s when s.EndsWith greaterThanOrEqualSuffix && s.Length > greaterThanOrEqualSuffix.Length -> GreaterThanOrEqual (prefix greaterThanOrEqualSuffix s)
120-
| s when s.EndsWith gteSuffix && s.Length > gteSuffix.Length -> GreaterThanOrEqual (prefix gteSuffix s)
121-
| s when s.EndsWith greaterThanSuffix && s.Length > greaterThanSuffix.Length -> GreaterThan (prefix greaterThanSuffix s)
122-
| s when s.EndsWith gtSuffix && s.Length > gtSuffix.Length -> GreaterThan (prefix gtSuffix s)
123-
| s when s.EndsWith lessThanOrEqualSuffix && s.Length > lessThanOrEqualSuffix.Length -> LessThanOrEqual (prefix lessThanOrEqualSuffix s)
124-
| s when s.EndsWith lteSuffix && s.Length > lteSuffix.Length -> LessThanOrEqual (prefix lteSuffix s)
125-
| s when s.EndsWith lessThanSuffix && s.Length > lessThanSuffix.Length -> LessThan (prefix lessThanSuffix s)
126-
| s when s.EndsWith ltSuffix && s.Length > ltSuffix.Length -> LessThan (prefix ltSuffix s)
127-
| s when s.EndsWith inSuffix && s.Length > inSuffix.Length -> In (prefix inSuffix s)
41+
| s when s.EndsWith FilterSuffixConstants.CI.EndsWithSuffix && s.Length > FilterSuffixConstants.CI.EndsWithSuffix.Length -> EndsWith (prefix FilterSuffixConstants.CI.EndsWithSuffix s, StringComparer.OrdinalIgnoreCase)
42+
| s when s.EndsWith FilterSuffixConstants.CI.EWSuffix && s.Length > FilterSuffixConstants.CI.EWSuffix.Length -> EndsWith (prefix FilterSuffixConstants.CI.EWSuffix s, StringComparer.OrdinalIgnoreCase)
43+
| s when s.EndsWith FilterSuffixConstants.CI.StartsWithSuffix && s.Length > FilterSuffixConstants.CI.StartsWithSuffix.Length -> StartsWith (prefix FilterSuffixConstants.CI.StartsWithSuffix s, StringComparer.OrdinalIgnoreCase)
44+
| s when s.EndsWith FilterSuffixConstants.CI.SWSuffix && s.Length > FilterSuffixConstants.CI.SWSuffix.Length -> StartsWith (prefix FilterSuffixConstants.CI.SWSuffix s, StringComparer.OrdinalIgnoreCase)
45+
| s when s.EndsWith FilterSuffixConstants.CI.ContainsSuffix && s.Length > FilterSuffixConstants.CI.ContainsSuffix.Length -> Contains (prefix FilterSuffixConstants.CI.ContainsSuffix s, StringComparer.OrdinalIgnoreCase)
46+
| s when s.EndsWith FilterSuffixConstants.CI.EqualsSuffix && s.Length > FilterSuffixConstants.CI.EqualsSuffix.Length -> StringEquals (prefix FilterSuffixConstants.CI.EqualsSuffix s, StringComparer.OrdinalIgnoreCase)
47+
| s when s.EndsWith FilterSuffixConstants.CI.EQSuffix && s.Length > FilterSuffixConstants.CI.EQSuffix.Length -> StringEquals (prefix FilterSuffixConstants.CI.EQSuffix s, StringComparer.OrdinalIgnoreCase)
48+
| s when s.EndsWith FilterSuffixConstants.GreaterThanOrEqualSuffix && s.Length > FilterSuffixConstants.GreaterThanOrEqualSuffix.Length -> GreaterThanOrEqual (prefix FilterSuffixConstants.GreaterThanOrEqualSuffix s)
49+
| s when s.EndsWith FilterSuffixConstants.GTESuffix && s.Length > FilterSuffixConstants.GTESuffix.Length -> GreaterThanOrEqual (prefix FilterSuffixConstants.GTESuffix s)
50+
| s when s.EndsWith FilterSuffixConstants.GreaterThanSuffix && s.Length > FilterSuffixConstants.GreaterThanSuffix.Length -> GreaterThan (prefix FilterSuffixConstants.GreaterThanSuffix s)
51+
| s when s.EndsWith FilterSuffixConstants.GTSuffix && s.Length > FilterSuffixConstants.GTSuffix.Length -> GreaterThan (prefix FilterSuffixConstants.GTSuffix s)
52+
| s when s.EndsWith FilterSuffixConstants.LessThanOrEqualSuffix && s.Length > FilterSuffixConstants.LessThanOrEqualSuffix.Length -> LessThanOrEqual (prefix FilterSuffixConstants.LessThanOrEqualSuffix s)
53+
| s when s.EndsWith FilterSuffixConstants.LTESuffix && s.Length > FilterSuffixConstants.LTESuffix.Length -> LessThanOrEqual (prefix FilterSuffixConstants.LTESuffix s)
54+
| s when s.EndsWith FilterSuffixConstants.LessThanSuffix && s.Length > FilterSuffixConstants.LessThanSuffix.Length -> LessThan (prefix FilterSuffixConstants.LessThanSuffix s)
55+
| s when s.EndsWith FilterSuffixConstants.LTSuffix && s.Length > FilterSuffixConstants.LTSuffix.Length -> LessThan (prefix FilterSuffixConstants.LTSuffix s)
56+
| s when s.EndsWith FilterSuffixConstants.InSuffix && s.Length > FilterSuffixConstants.InSuffix.Length -> In (prefix FilterSuffixConstants.InSuffix s)
12857
| s -> Equals s
12958

13059
let (|EquatableValue|NonEquatableValue|) v =

0 commit comments

Comments
 (0)