11// The MIT License (MIT)
2- namespace FSharp.Data.GraphQL
2+ namespace FSharp.Data.GraphQL
33
44open System
55open System.Collections .Generic
6- open System.Collections .Immutable
7- open System.Collections .ObjectModel
86open FsToolkit.ErrorHandling
97open FSharp.Data .GraphQL .Types
108
11- type InputRoot =
12- | Variable of VarDef : VarDef
13- | Argument of ArgDef : InputFieldDef
14-
15- type ErrorKind =
16- | InputCoercion
17- | InputObjectValidation
18- | Execution
19-
20- type internal CoercionError =
21- {
22- InnerError : IGQLError
23- ErrorKind : ErrorKind
24- ObjectType : string voption
25- FieldType : string voption
26- Path : FieldPath
27- }
28- interface IGQLError with
29-
30- member this.Message = this.InnerError.Message
31-
32- interface IGQLErrorExtensions with
33-
34- member this.Extensions =
9+ type InputSource =
10+ | Variable of VarDef : VarDef
11+ | Argument of ArgDef : InputFieldDef
12+ | Unknown
3513
36- [
37- yield KeyValuePair( " kind" , this.ErrorKind |> box)
38- if this.ObjectType.IsSome then yield KeyValuePair( " objectType" , this.ObjectType.Value |> box)
39- if this.FieldType.IsSome then yield KeyValuePair( " fieldType" , this.FieldType.Value |> box)
14+ [<Struct>]
15+ type internal ObjectFieldErrorDetails = { ObjectDef : InputDef ; FieldDef : InputFieldDef voption }
4016
41- match this.Path with
42- | [] -> ()
43- | path -> yield KeyValuePair ( " path " , path |> Seq.rev |> box )
17+ type internal IInputSourceError =
18+ inherit IGQLError
19+ abstract member InputSource : InputSource with get , set
4420
45- match this.InnerError with
46- | :? IGQLErrorExtensions as ext ->
47- match ext.Extensions with
48- | ValueSome extensions -> yield ! extensions
49- | ValueNone -> ()
50- | _ -> ()
51- ]
52- |> Dictionary<_,_>
53- |> ReadOnlyDictionary<_,_>
54- :> IReadOnlyDictionary< string, obj>
55- |> ValueSome
21+ type internal CoercionError = {
22+ mutable InputSource : InputSource
23+ Message : string
24+ ErrorKind : ErrorKind
25+ Path : FieldPath
26+ FieldErrorDetails : ObjectFieldErrorDetails voption
27+ } with
5628
57- [<Struct>]
58- type internal ObjectFieldErrorDetails = {
59- ObjectDef : InputObjectDef
60- FieldDef : InputFieldDef voption
61- }
62-
63- type internal CoerceVariableError =
64- {
65- Message : string
66- ErrorKind : ErrorKind
67- Variable : VarDef
68- Path : FieldPath
69- FieldErrorDetails : ObjectFieldErrorDetails voption
70- }
7129 interface IGQLError with
7230
7331 member this.Message = this.Message
@@ -77,35 +35,46 @@ type internal CoerceVariableError =
7735 member this.Extensions =
7836
7937 [
80- yield KeyValuePair( " kind" , this.ErrorKind |> box)
81- yield KeyValuePair( " variableName" , this.Variable.Name |> box)
82- yield KeyValuePair( " variableType" , ( this.Variable.TypeDef :?> NamedDef) .Name |> box)
38+ yield KeyValuePair ( CustomErrorFields.Kind, this.ErrorKind |> box)
8339 match this.Path with
8440 | [] -> ()
85- | path -> yield KeyValuePair( " path" , path |> Seq.rev |> box)
41+ | path -> yield KeyValuePair ( CustomErrorFields.Path, path |> List.rev |> box)
42+
43+ match this.InputSource with
44+ | Variable varDef ->
45+ yield KeyValuePair ( CustomErrorFields.VariableName, varDef.Name |> box)
46+ yield KeyValuePair ( CustomErrorFields.VariableType, ( string varDef.TypeDef) |> box)
47+ | Argument argDef ->
48+ yield KeyValuePair ( CustomErrorFields.ArgumentName, argDef.Name |> box)
49+ yield KeyValuePair ( CustomErrorFields.ArgumentType, ( string argDef.TypeDef) |> box)
50+ | Unknown -> ()
8651
8752 match this.FieldErrorDetails with
8853 | ValueSome details ->
89- yield KeyValuePair( " objectType " , details.ObjectDef.Name |> box)
54+ yield KeyValuePair ( CustomErrorFields.ObjectType , ( string details.ObjectDef) |> box)
9055 match details.FieldDef with
91- | ValueSome fieldDef ->
92- yield KeyValuePair( " fieldType" , ( fieldDef.TypeDef :?> NamedDef) .Name|> box)
56+ | ValueSome fieldDef -> yield KeyValuePair ( CustomErrorFields.FieldType, ( string fieldDef.TypeDef) |> box)
9357 | ValueNone -> ()
9458 | ValueNone -> ()
9559 ]
96- |> Dictionary<_,_>
97- |> ReadOnlyDictionary<_,_>
60+ |> Dictionary<_, _>
9861 :> IReadOnlyDictionary< string, obj>
9962 |> ValueSome
10063
101- type internal CoerceVariableErrorWrapper =
102- {
103- InnerError : IGQLError
104- ErrorKind : ErrorKind
105- Variable: VarDef
106- Path : FieldPath
107- FieldErrorDetails : ObjectFieldErrorDetails voption
108- }
64+ interface IInputSourceError with
65+
66+ member this.InputSource
67+ with get () = this.InputSource
68+ and set ( value ) = this.InputSource <- value
69+
70+ type internal CoercionErrorWrapper = {
71+ mutable InputSource : InputSource
72+ InnerError : IGQLError
73+ ErrorKind : ErrorKind
74+ Path : FieldPath
75+ FieldErrorDetails : ObjectFieldErrorDetails voption
76+ } with
77+
10978 interface IGQLError with
11079
11180 member this.Message = this.InnerError.Message
@@ -115,19 +84,25 @@ type internal CoerceVariableErrorWrapper =
11584 member this.Extensions =
11685
11786 [
118- yield KeyValuePair( " kind" , this.ErrorKind |> box)
119- yield KeyValuePair( " variableName" , this.Variable.Name |> box)
120- yield KeyValuePair( " variableType" , ( this.Variable.TypeDef :?> NamedDef) .Name |> box)
87+ yield KeyValuePair ( CustomErrorFields.Kind, this.ErrorKind |> box)
12188 match this.Path with
12289 | [] -> ()
123- | path -> yield KeyValuePair( " path" , path |> Seq.rev |> box)
90+ | path -> yield KeyValuePair ( CustomErrorFields.Path, path |> List.rev |> box)
91+
92+ match this.InputSource with
93+ | Variable varDef ->
94+ yield KeyValuePair ( CustomErrorFields.VariableName, varDef.Name |> box)
95+ yield KeyValuePair ( CustomErrorFields.VariableType, ( string varDef.TypeDef) |> box)
96+ | Argument argDef ->
97+ yield KeyValuePair ( CustomErrorFields.ArgumentName, argDef.Name |> box)
98+ yield KeyValuePair ( CustomErrorFields.ArgumentType, ( string argDef.TypeDef) |> box)
99+ | Unknown -> ()
124100
125101 match this.FieldErrorDetails with
126102 | ValueSome details ->
127- yield KeyValuePair( " objectType " , details.ObjectDef.Name |> box)
103+ yield KeyValuePair ( CustomErrorFields.ObjectType , ( string details.ObjectDef) |> box)
128104 match details.FieldDef with
129- | ValueSome fieldDef ->
130- yield KeyValuePair( " fieldType" , ( fieldDef.TypeDef :?> NamedDef) .Name|> box)
105+ | ValueSome fieldDef -> yield KeyValuePair ( CustomErrorFields.FieldType, ( string fieldDef.TypeDef) |> box)
131106 | ValueNone -> ()
132107 | ValueNone -> ()
133108
@@ -138,43 +113,12 @@ type internal CoerceVariableErrorWrapper =
138113 | ValueNone -> ()
139114 | _ -> ()
140115 ]
141- |> Dictionary<_,_>
142- |> ReadOnlyDictionary<_,_>
116+ |> Dictionary<_, _>
143117 :> IReadOnlyDictionary< string, obj>
144118 |> ValueSome
145119
146- type internal CoerceArgumentError =
147- {
148- InnerError : IGQLError
149- ArgumentName : string
150- TypeName : string
151- Path : FieldPath
152- }
153- interface IGQLError with
154-
155- member this.Message = this.InnerError.Message
156-
157- interface IGQLErrorExtensions with
158-
159- member this.Extensions =
160-
161- [
162- yield KeyValuePair( " argumentName" , this.ArgumentName |> box)
163- yield KeyValuePair( " typeName" , this.TypeName |> box)
164-
165- match this.Path with
166- | [] -> ()
167- | path -> yield KeyValuePair( " path" , path |> Seq.rev |> box)
168-
169- match this.InnerError with
170- | :? IGQLErrorExtensions as ext ->
171- match ext.Extensions with
172- | ValueSome extensions -> yield ! extensions
173- | ValueNone -> ()
174- | _ -> ()
175- ]
176- |> Dictionary<_,_>
177- |> ReadOnlyDictionary<_,_>
178- :> IReadOnlyDictionary< string, obj>
179- |> ValueSome
120+ interface IInputSourceError with
180121
122+ member this.InputSource
123+ with get () = this.InputSource
124+ and set ( value ) = this.InputSource <- value
0 commit comments