-
Notifications
You must be signed in to change notification settings - Fork 74
Expand file tree
/
Copy pathTypeSystemExtensions.fs
More file actions
69 lines (56 loc) · 2.51 KB
/
Copy pathTypeSystemExtensions.fs
File metadata and controls
69 lines (56 loc) · 2.51 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
namespace FSharp.Data.GraphQL.Server.Middleware
open System
open System.Collections.Immutable
open System.Linq
open FSharp.Data.GraphQL.Types
/// Contains extensions for the type system.
[<AutoOpen>]
module TypeSystemExtensions =
type FieldDef<'Val> with
/// <summary>
/// Creates a new field definition based on the existing one, containing
/// the existing metadata information, plus a new entry used to calculate the query
/// weight by the QueryWeightMiddleware.
/// </summary>
/// <param name="weight">A float value representing the weight that this field have on the query.</param>
member this.WithQueryWeight (weight : float) : FieldDef<'Val> = this.WithMetadata (this.Metadata.Add ("queryWeight", weight))
open ObjectListFilter.Operators
type ExecutionInfo with
member this.ResolveAbstractionFilter (typeMap : TypeMap) =
match this.Kind with
| ResolveAbstraction typeFields ->
match this.ReturnDef with
| :? UnionDef as union when
union.Options
|> Seq.map _.Name
|> Seq.sort
|> _.SequenceEqual(typeFields.Keys |> Seq.sort)
->
ValueNone
| _ ->
let getType name = typeMap[name].Type
typeFields.Keys
|> Seq.map getType
|> Seq.toList
|> OfTypes
|> ValueSome
| _ -> ValueNone
type ResolveFieldContext with
/// <summary>
/// Gets the filter argument value for this field, if it does have one.
/// Field argument is defined by the ObjectFilterMiddleware.
/// </summary>
member this.Filter =
match this.Args.TryGetValue "filter" with
| true, (:? ObjectListFilter as f) ->
match this.ExecutionInfo.ResolveAbstractionFilter (this.Context.Schema.TypeMap) with
| ValueSome ofTypes -> ValueSome (ofTypes &&& f)
| ValueNone -> ValueSome f
| false, _ -> ValueNone
| true, _ -> raise (InvalidOperationException "Invalid filter argument type.")
type ObjectListFilters = ImmutableDictionary<obj list, ObjectListFilter>
type ExecutionContext with
/// <summary>
/// Gets the filters applied to the lists.
/// </summary>
member this.Filters = this.Metadata.TryFind<ObjectListFilters> "filters"