File tree Expand file tree Collapse file tree 2 files changed +14
-2
lines changed
src/FSharp.Data.GraphQL.Server.Middleware Expand file tree Collapse file tree 2 files changed +14
-2
lines changed Original file line number Diff line number Diff line change 11namespace FSharp.Data.GraphQL.Server.Middleware
22
3+ open System
4+
35/// A filter definition for a field value.
46type 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.
2426module ObjectListFilter =
2527 /// Contains operators for building and comparing ObjectListFilter values.
Original file line number Diff line number Diff 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
You can’t perform that action at this time.
0 commit comments