Skip to content

Commit 2e4699f

Browse files
xperiandriViktor Tochonov
authored andcommitted
Added OfTypes case to ObjectListFilter
1 parent e7fa923 commit 2e4699f

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
namespace FSharp.Data.GraphQL.Server.Middleware
22

3+
open System
4+
35
/// A filter definition for a field value.
46
type FieldFilter<'Val> =
57
{ FieldName : string
@@ -16,10 +18,10 @@ type ObjectListFilter =
1618
| StartsWith of FieldFilter<string>
1719
| EndsWith of FieldFilter<string>
1820
| Contains of FieldFilter<string>
21+
| OfTypes of FieldFilter<Type list>
1922
| FilterField of FieldFilter<ObjectListFilter>
2023
| NoFilter
2124

22-
2325
/// Contains tooling for working with ObjectListFilter.
2426
module ObjectListFilter =
2527
/// Contains operators for building and comparing ObjectListFilter values.

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

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,17 @@ module TypeSystemExtensions =
3131
/// </summary>
3232
member this.Filter =
3333
match this.Args.TryGetValue "filter" with
34-
| true, (:? ObjectListFilter as f) -> ValueSome f
34+
| true, (:? ObjectListFilter as f) ->
35+
match this.ExecutionInfo.Kind with
36+
| ResolveAbstraction typeFields ->
37+
let getType name =
38+
match this.Context.Schema.TypeMap.TryFind name with
39+
| ValueSome tdef -> tdef.Type
40+
| ValueNone -> raise (MalformedGQLQueryException ($"Type '{name}' not found in schema."))
41+
match typeFields.Keys |> Seq.map getType |> Seq.toList with
42+
| [] -> ValueNone
43+
| filters -> f &&& (OfTypes { FieldName = "__typename"; Value = filters }) |> ValueSome
44+
| _ -> ValueSome f
3545
| false, _ -> ValueNone
3646
| true, _ -> raise (InvalidOperationException "Invalid filter argument type.")
3747

0 commit comments

Comments
 (0)