forked from fsprojects/FSharp.Data.GraphQL
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathErrorTypes.fs
More file actions
126 lines (100 loc) · 4.48 KB
/
Copy pathErrorTypes.fs
File metadata and controls
126 lines (100 loc) · 4.48 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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
// The MIT License (MIT)
namespace FSharp.Data.GraphQL
open System
open System.Collections.Generic
open FsToolkit.ErrorHandling
open FSharp.Data.GraphQL.Errors
open FSharp.Data.GraphQL.Types
type InputSource =
| Variable of VarDef : VarDef
| Argument of ArgDef : InputFieldDef
| Unknown
[<Struct>]
type internal ObjectFieldErrorDetails = { ObjectDef : InputDef; FieldDef : InputFieldDef voption }
type internal IInputSourceError =
inherit IGQLError
abstract member InputSource : InputSource with get, set
type internal CoercionError = {
mutable InputSource : InputSource
Message : string
ErrorKind : ErrorKind
Path : FieldPath
FieldErrorDetails : ObjectFieldErrorDetails voption
} with
interface IGQLError with
member this.Message = this.Message
interface IGQLErrorExtensions with
member this.Extensions =
[
yield KeyValuePair (CustomErrorFields.Kind, this.ErrorKind |> box)
match this.Path with
| [] -> ()
| path -> yield KeyValuePair (CustomErrorFields.Path, normalizeErrorPath path)
match this.InputSource with
| Variable varDef ->
yield KeyValuePair (CustomErrorFields.VariableName, varDef.Name |> box)
yield KeyValuePair (CustomErrorFields.VariableType, (string varDef.TypeDef) |> box)
| Argument argDef ->
yield KeyValuePair (CustomErrorFields.ArgumentName, argDef.Name |> box)
yield KeyValuePair (CustomErrorFields.ArgumentType, (string argDef.TypeDef) |> box)
| Unknown -> ()
match this.FieldErrorDetails with
| ValueSome details ->
yield KeyValuePair (CustomErrorFields.ObjectType, (string details.ObjectDef) |> box)
match details.FieldDef with
| ValueSome fieldDef -> yield KeyValuePair (CustomErrorFields.FieldType, (string fieldDef.TypeDef) |> box)
| ValueNone -> ()
| ValueNone -> ()
]
|> Dictionary<_, _>
:> IReadOnlyDictionary<string, obj>
|> ValueSome
interface IInputSourceError with
member this.InputSource
with get () = this.InputSource
and set (value) = this.InputSource <- value
type internal CoercionErrorWrapper = {
mutable InputSource : InputSource
InnerError : IGQLError
ErrorKind : ErrorKind
Path : FieldPath
FieldErrorDetails : ObjectFieldErrorDetails voption
} with
interface IGQLError with
member this.Message = this.InnerError.Message
interface IGQLErrorExtensions with
member this.Extensions =
[
yield KeyValuePair (CustomErrorFields.Kind, this.ErrorKind |> box)
match this.Path with
| [] -> ()
| path -> yield KeyValuePair (CustomErrorFields.Path, normalizeErrorPath path)
match this.InputSource with
| Variable varDef ->
yield KeyValuePair (CustomErrorFields.VariableName, varDef.Name |> box)
yield KeyValuePair (CustomErrorFields.VariableType, (string varDef.TypeDef) |> box)
| Argument argDef ->
yield KeyValuePair (CustomErrorFields.ArgumentName, argDef.Name |> box)
yield KeyValuePair (CustomErrorFields.ArgumentType, (string argDef.TypeDef) |> box)
| Unknown -> ()
match this.FieldErrorDetails with
| ValueSome details ->
yield KeyValuePair (CustomErrorFields.ObjectType, (string details.ObjectDef) |> box)
match details.FieldDef with
| ValueSome fieldDef -> yield KeyValuePair (CustomErrorFields.FieldType, (string fieldDef.TypeDef) |> box)
| ValueNone -> ()
| ValueNone -> ()
match this.InnerError with
| :? IGQLErrorExtensions as ext ->
match ext.Extensions with
| ValueSome extensions -> yield! extensions
| ValueNone -> ()
| _ -> ()
]
|> Dictionary<_, _>
:> IReadOnlyDictionary<string, obj>
|> ValueSome
interface IInputSourceError with
member this.InputSource
with get () = this.InputSource
and set (value) = this.InputSource <- value