-
Notifications
You must be signed in to change notification settings - Fork 75
/
Copy pathSchemaDefinitions.fs
1462 lines (1351 loc) · 87.3 KB
/
SchemaDefinitions.fs
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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// The MIT License (MIT)
// Copyright (c) 2016 Bazinga Technologies Inc
namespace FSharp.Data.GraphQL.Types
open System
open System.Reflection
open System.Collections.Generic
open System.Text.Json
open FSharp.Data.GraphQL
open FSharp.Data.GraphQL.Ast
open FSharp.Data.GraphQL.Extensions
open FSharp.Data.GraphQL.Types
open FSharp.Data.GraphQL.Validation
open FSharp.Quotations
[<AutoOpen>]
module SchemaDefinitions =
module Errors =
type InputValue with
member inputValue.GetCoerceError(destinationType) =
let getMessage inputType value = $"Inline value '{value}' of type %s{inputType} cannot be converted into %s{destinationType}"
let message =
match inputValue with
| IntValue value -> getMessage "integer" value
| FloatValue value -> getMessage "float" value
| BooleanValue value -> getMessage "boolean" value
| StringValue value -> getMessage "string" value
| NullValue -> $"Inline value 'null' cannot be converted into {destinationType}"
| EnumValue value -> getMessage "enum" value
| value -> raise <| NotSupportedException $"{value} cannot be passed as scalar input"
Error [{ new IGQLError with member _.Message = message }]
member inputValue.GetCoerceRangeError(destinationType, minValue, maxValue) =
let getMessage inputType value = $"Inline value '{value}' of type %s{inputType} cannot be converted into %s{destinationType} of range from {minValue} to {maxValue}"
let message =
match inputValue with
| IntValue value -> getMessage "integer" value
| FloatValue value -> getMessage "float" value
| BooleanValue value -> getMessage "boolean" value
| StringValue value -> getMessage "string" value
| NullValue -> $"Inline value 'null' cannot be converted into {destinationType}"
| EnumValue value -> getMessage "enum" value
| value -> raise <| NotSupportedException $"{value} cannot be passed as scalar input"
Error [{ new IGQLError with member _.Message = message }]
type JsonElement with
member e.GetDeserializeError(destinationType, minValue, maxValue ) =
let jsonValue = match e.ValueKind with JsonValueKind.String -> e.GetString() | _ -> e.GetRawText()
Error [{ new IGQLError with member _.Message = $"JSON value '{jsonValue}' of kind '{e.ValueKind}' cannot be deserialized into %s{destinationType} of range from {minValue} to {maxValue}" }]
member e.GetDeserializeError(destinationType) =
let jsonValue = match e.ValueKind with JsonValueKind.String -> e.GetString() | _ -> e.GetRawText()
Error [{ new IGQLError with member _.Message = $"JSON value '{jsonValue}' of kind '{e.ValueKind}' cannot be deserialized into %s{destinationType}" }]
let getParseRangeError (destinationType, minValue, maxValue) value =
Error [{ new IGQLError with member _.Message = $"Inline value '%s{value}' cannot be parsed into %s{destinationType} of range from {minValue} to {maxValue}" }]
let getParseError destinationType value =
Error [{ new IGQLError with member _.Message = $"Inline value '%s{value}' cannot be parsed into %s{destinationType}" }]
open System.Globalization
open Errors
/// Tries to convert any value to int.
let coerceIntValue (x : obj) : int option =
match x with
| null -> None
| other ->
try
Some(System.Convert.ToInt32 other)
with _ -> None
/// Tries to convert any value to int64.
let coerceLongValue (x : obj) : int64 option =
match x with
| null -> None
| :? int as i -> Some (int64 i)
| :? int64 as l -> Some(l)
| :? double as d -> Some(int64 d)
| :? string as s ->
match Int64.TryParse(s) with
| true, i -> Some i
| false, _ -> None
| :? bool as b ->
Some(if b then 1L else 0L)
| other ->
try
Some(System.Convert.ToInt64 other)
with _ -> None
/// Tries to convert any value to double.
let coerceFloatValue (x : obj) : double option =
match x with
| null -> None
| :? int as i -> Some(double i)
| :? int64 as l -> Some(double l)
| :? double as d -> Some d
| :? string as s ->
match Double.TryParse(s) with
| true, i -> Some i
| false, _ -> None
| :? bool as b ->
Some(if b then 1.
else 0.)
| other ->
try
Some(System.Convert.ToDouble other)
with _ -> None
/// Tries to convert any value to bool.
let coerceBoolValue (x : obj) : bool option =
match x with
| null -> None
| other ->
try
Some(System.Convert.ToBoolean other)
with _ -> None
/// Tries to convert any value to URI.
let coerceUriValue (x : obj) : Uri option =
match x with
| null -> None
| :? Uri as u -> Some u
| :? string as s ->
match Uri.TryCreate(s, UriKind.RelativeOrAbsolute) with
| true, uri -> Some uri
| false, _ -> None
| other -> None
/// Tries to convert any value to DateTimeOffset.
let coerceDateTimeOffsetValue (x : obj) : DateTimeOffset option =
match x with
| null -> None
| :? DateTimeOffset as d -> Some d
| :? DateTime as d -> Some (DateTimeOffset d)
| :? string as s ->
match DateTimeOffset.TryParse(s) with
| true, date -> Some date
| false, _ -> None
| other -> None
/// Tries to convert any value to DateOnly.
let coerceDateOnlyValue (x : obj) : DateOnly option =
match x with
| null -> None
| :? DateOnly as d -> Some d
| :? DateTime as d -> Some (DateOnly.FromDateTime d)
| :? string as s ->
match DateOnly.TryParse(s) with
| true, date -> Some date
| false, _ -> None
| other -> None
/// Tries to convert any value to Guid.
let coerceGuidValue (x : obj) : Guid option =
match x with
| null -> None
| :? Guid as g -> Some g
| :? string as s ->
match Guid.TryParse(s) with
| true, guid -> Some guid
| false, _ -> None
| other -> None
/// Check if provided obj value is an Option and extract its wrapped value as object if possible
let private (|Option|_|) (x : obj) =
if isNull x then None
else
let t = x.GetType().GetTypeInfo()
if t.IsGenericType && t.GetGenericTypeDefinition() = typedefof<option<_>> then
t.GetDeclaredProperty("Value").GetValue(x) |> Some
else None
/// Tries to convert any value to string.
let coerceStringValue (x : obj) : string option =
match x with
| null -> None
| :? string as s -> Some s
| :? bool as b ->
Some(if b then "true"
else "false")
| Option o -> Some(o.ToString())
| _ -> Some(x.ToString())
/// Tries to convert any value to generic type parameter.
let coerceIdValue (x : obj) : string option =
match x with
| null -> None
| :? string as s -> Some s
| Option o -> Some(string o)
| _ -> Some(string x)
/// Tries to resolve AST query input to int.
let coerceIntInput =
let destinationType = "integer"
function
| Variable e when e.ValueKind = JsonValueKind.Number ->
match e.TryGetInt32() with
| true, value -> Ok value
| false, _ -> e.GetDeserializeError(destinationType, Int32.MinValue, Int32.MaxValue)
| Variable e when e.ValueKind = JsonValueKind.True -> Ok 1
| Variable e when e.ValueKind = JsonValueKind.False -> Ok 0
| Variable e -> e.GetDeserializeError (destinationType, Int32.MinValue, Int32.MaxValue)
| InlineConstant (IntValue i) -> Ok (int i)
| InlineConstant (BooleanValue b) -> Ok (if b then 1 else 0)
| InlineConstant value -> value.GetCoerceRangeError(destinationType, Int32.MinValue, Int32.MaxValue)
/// Tries to resolve AST query input to int64.
let coerceLongInput =
let destinationType = "integer"
function
| Variable e when e.ValueKind = JsonValueKind.Number ->
match e.TryGetInt64() with
| true, value -> Ok value
| false, _ -> e.GetDeserializeError(destinationType, Int64.MinValue, Int64.MaxValue)
| Variable e when e.ValueKind = JsonValueKind.True -> Ok 1L
| Variable e when e.ValueKind = JsonValueKind.False -> Ok 0L
| Variable e -> e.GetDeserializeError (destinationType, Int64.MinValue, Int64.MaxValue)
| InlineConstant (IntValue i) -> Ok (int64 i)
| InlineConstant (BooleanValue b) -> Ok(if b then 1L else 0L)
| InlineConstant value -> value.GetCoerceRangeError(destinationType, Int64.MinValue, Int64.MaxValue)
/// Tries to resolve AST query input to double.
let coerceFloatInput =
let destinationType = "float"
function
| Variable e when e.ValueKind = JsonValueKind.Number -> Ok (e.GetDouble())
| Variable e when e.ValueKind = JsonValueKind.True -> Ok 1.
| Variable e when e.ValueKind = JsonValueKind.False -> Ok 0.
| Variable e -> e.GetDeserializeError (destinationType, Double.MinValue, Double.MaxValue)
| InlineConstant (IntValue i) -> Ok(double i)
| InlineConstant (FloatValue f) -> Ok f
| InlineConstant (BooleanValue b) -> Ok(if b then 1. else 0.)
| InlineConstant value -> value.GetCoerceRangeError(destinationType, Double.MinValue, Double.MaxValue)
/// Tries to resolve AST query input to string.
let coerceStringInput =
let destinationType = "string"
function
| Variable e ->
match e.ValueKind with
| JsonValueKind.String -> Ok (e.GetString())
| JsonValueKind.True
| JsonValueKind.False
| JsonValueKind.Number -> Ok (e.GetRawText())
| _ -> e.GetDeserializeError destinationType
| InlineConstant (IntValue i) -> Ok(i.ToString(CultureInfo.InvariantCulture))
| InlineConstant (FloatValue f) -> Ok(f.ToString(CultureInfo.InvariantCulture))
| InlineConstant (StringValue s) -> Ok s
| InlineConstant (BooleanValue b) -> Ok (if b then "true" else "false")
| InlineConstant (EnumValue e) -> Ok e
| InlineConstant value -> value.GetCoerceError destinationType
let coerceEnumInput =
function
| EnumValue e -> Ok e
| value -> value.GetCoerceError "enum"
/// Tries to resolve AST query input to bool.
let coerceBoolInput =
let destinationType = "boolean"
function
| Variable e when e.ValueKind = JsonValueKind.True -> Ok true
| Variable e when e.ValueKind = JsonValueKind.False -> Ok false
| Variable e when e.ValueKind = JsonValueKind.Number -> Ok (if e.GetDouble() = 0. then false else true)
| Variable e -> e.GetDeserializeError destinationType
| InlineConstant (IntValue i) -> Ok(if i = 0L then false else true)
| InlineConstant (FloatValue f) -> Ok(if f = 0. then false else true)
| InlineConstant (BooleanValue b) -> Ok b
| InlineConstant value -> value.GetCoerceError destinationType
/// Tries to resolve AST query input to provided generic type.
let coerceIdInput input : Result<string, IGQLError list> =
let destinationType = "identifier"
match input with
| Variable e when e.ValueKind = JsonValueKind.String -> Ok (e.GetString())
| Variable e when e.ValueKind = JsonValueKind.Number ->
try
e.GetInt64() |> ignore
Ok (e.GetRawText())
with :? FormatException ->
e.GetDeserializeError(destinationType, Int64.MinValue, Int64.MaxValue)
| Variable e -> e.GetDeserializeError destinationType
| InlineConstant (IntValue i) -> Ok(string i)
| InlineConstant (FloatValue i) -> (FloatValue i).GetCoerceRangeError(destinationType, Int64.MinValue, Int64.MaxValue)
| InlineConstant (StringValue s) -> Ok s
| InlineConstant value -> value.GetCoerceError destinationType
/// Tries to resolve AST query input to URI.
let coerceUriInput =
let destinationType = "URI"
function
| Variable e when e.ValueKind = JsonValueKind.String ->
match Uri.TryCreate(e.GetString(), UriKind.RelativeOrAbsolute) with
| true, uri -> Ok uri
| false, _ -> e.GetDeserializeError destinationType
| Variable e -> e.GetDeserializeError destinationType
| InlineConstant (StringValue s) ->
match Uri.TryCreate(s, UriKind.RelativeOrAbsolute) with
| true, uri -> Ok uri
| false, _ -> getParseError destinationType s
| InlineConstant value -> value.GetCoerceError destinationType
/// Tries to resolve AST query input to DateTimeOffset.
let coerceDateTimeOffsetInput =
let destinationType = "date and time with offset"
function
| Variable e when e.ValueKind = JsonValueKind.String ->
let s = e.GetString()
match DateTimeOffset.TryParse(s) with
| true, date -> Ok date
| false, _ -> e.GetDeserializeError destinationType
| Variable e -> e.GetDeserializeError destinationType
| InlineConstant (StringValue s) ->
match DateTimeOffset.TryParse(s) with
| true, date -> Ok date
| false, _ -> getParseRangeError(destinationType, DateTimeOffset.MinValue, DateTimeOffset.MaxValue) s
| InlineConstant value -> value.GetCoerceRangeError(destinationType, DateTimeOffset.MinValue, DateTimeOffset.MaxValue)
/// Tries to resolve AST query input to DateOnly.
let coerceDateOnlyInput =
let destinationType = "date"
function
| Variable e when e.ValueKind = JsonValueKind.String ->
let s = e.GetString()
match DateOnly.TryParse(s) with
| true, date -> Ok date
| false, _ -> e.GetDeserializeError destinationType
| Variable e -> e.GetDeserializeError destinationType
| InlineConstant (StringValue s) ->
match DateOnly.TryParse(s) with
| true, date -> Ok date
| false, _ -> getParseRangeError(destinationType, DateOnly.MinValue, DateOnly.MaxValue) s
| InlineConstant value -> value.GetCoerceRangeError(destinationType, DateOnly.MinValue, DateOnly.MaxValue)
/// Tries to resolve AST query input to Guid.
let coerceGuidInput =
let destinationType = "GUID"
function
| Variable e when e.ValueKind = JsonValueKind.String ->
let s = e.GetString()
match Guid.TryParse(s) with
| true, guid -> Ok guid
| false, _ -> e.GetDeserializeError destinationType
| Variable e -> e.GetDeserializeError destinationType
| InlineConstant (StringValue s) ->
match Guid.TryParse(s) with
| true, guid -> Ok guid
| false, _ -> getParseError destinationType s
| InlineConstant value -> value.GetCoerceError destinationType
/// Wraps a GraphQL type definition, allowing defining field/argument
/// to take option of provided value.
let Nullable(innerDef : #TypeDef<'Val>) : NullableDef<'Val> = upcast { NullableDefinition.OfType = innerDef }
/// Wraps a GraphQL type definition, allowing defining field/argument
/// to take voption of provided value.
let StructNullable(innerDef : #TypeDef<'Val>) : StructNullableDef<'Val> = upcast { StructNullableDefinition.OfType = innerDef }
/// Wraps a GraphQL type definition, allowing defining field/argument
/// to take collection of provided value.
let ListOf(innerDef : #TypeDef<'Val>) : ListOfDef<'Val, 'Seq> = upcast { ListOfDefinition.OfType = innerDef }
let internal variableOrElse other value (variables : IReadOnlyDictionary<string, obj>) =
match value with
// TODO: Use FSharp.Collection.Immutable
| VariableName variableName ->
match variables.TryGetValue variableName with
| true, value -> Ok value
| false, _ -> Error [{ new IGQLError with member _.Message = $"A variable '$%s{variableName}' not found" }]
| v -> other v
/// GraphQL type of int
let IntType : ScalarDefinition<int> =
{ Name = "Int"
Description =
Some
"The `Int` scalar type represents non-fractional signed whole numeric values. Int can represent values between -(2^31) and 2^31 - 1."
CoerceInput = coerceIntInput
CoerceOutput = coerceIntValue }
/// GraphQL type of long
let LongType : ScalarDefinition<int64> =
{ Name = "Long"
Description =
Some
"The `Long` scalar type represents non-fractional signed whole numeric values. Long can represent values between -(2^63) and 2^63 - 1."
CoerceInput = coerceLongInput
CoerceOutput = coerceLongValue }
/// GraphQL type of boolean
let BooleanType : ScalarDefinition<bool> =
{ Name = "Boolean"
Description = Some "The `Boolean` scalar type represents `true` or `false`."
CoerceInput = coerceBoolInput
CoerceOutput = coerceBoolValue }
/// GraphQL type of float
let FloatType : ScalarDefinition<double> =
{ Name = "Float"
Description =
Some
"The `Float` scalar type represents signed double-precision fractional values as specified by [IEEE 754](http://en.wikipedia.org/wiki/IEEE_floating_point)."
CoerceInput = coerceFloatInput
CoerceOutput = coerceFloatValue }
/// GraphQL type of string
let StringType : ScalarDefinition<string> =
{ Name = "String"
Description =
Some
"The `String` scalar type represents textual data, represented as UTF-8 character sequences. The `String` type is most often used by GraphQL to represent free-form human-readable text."
CoerceInput = coerceStringInput
CoerceOutput = coerceStringValue }
/// GraphQL type for custom identifier
let IDType : ScalarDefinition<string> =
{ Name = "ID"
Description =
Some
"The `ID` scalar type represents a unique identifier, often used to refetch an object or as key for a cache. The `ID` type appears in a JSON response as a String; however, it is not intended to be human-readable. When expected as an input type, any string (such as `\"4\"`) or integer (such as `4`) input value will be accepted as an ID."
CoerceInput = coerceIdInput
CoerceOutput = coerceIdValue }
let ObjType : ScalarDefinition<obj> = {
Name = "Object"
Description =
Some
"The `Object` scalar type represents textual data, represented as UTF-8 character sequences. The `String` type is most often used by GraphQL to represent free-form human-readable text."
CoerceInput = (fun o -> Ok (o))
CoerceOutput = (fun o -> Some (o))
}
/// GraphQL type for System.Uri
let UriType : ScalarDefinition<Uri> =
{ Name = "URI"
Description =
Some
"The `URI` scalar type represents a string resource identifier compatible with URI standard. The `URI` type appears in a JSON response as a String."
CoerceInput = coerceUriInput
CoerceOutput = coerceUriValue }
/// GraphQL type for System.DateTimeOffset
let DateTimeOffsetType : ScalarDefinition<DateTimeOffset> =
{ Name = "DateTimeOffset"
Description =
Some
"The `DateTimeOffset` scalar type represents a Date value with Time component. The `DateTimeOffset` type appears in a JSON response as a String representation compatible with ISO-8601 format."
CoerceInput = coerceDateTimeOffsetInput
CoerceOutput = coerceDateTimeOffsetValue }
/// GraphQL type for System.DateOnly
let DateOnlyType : ScalarDefinition<DateOnly> =
{ Name = "DateOnly"
Description =
Some
"The `DateOnly` scalar type represents a Date value without Time component. The `DateOnly` type appears in a JSON response as a `String` representation of full-date value as specified by [IETF 3339](https://www.ietf.org/rfc/rfc3339.txt)."
CoerceInput = coerceDateOnlyInput
CoerceOutput = coerceDateOnlyValue }
/// GraphQL type for System.Guid
let GuidType : ScalarDefinition<Guid> =
{ Name = "Guid"
Description =
Some
"The `Guid` scalar type represents a Globaly Unique Identifier value. It's a 128-bit long byte key, that can be serialized to string."
CoerceInput = coerceGuidInput
CoerceOutput = coerceGuidValue }
/// GraphQL @include directive.
let IncludeDirective : DirectiveDef =
{ Name = "include"
Description =
Some "Directs the executor to include this field or fragment only when the `if` argument is true."
Locations =
DirectiveLocation.FIELD ||| DirectiveLocation.FRAGMENT_SPREAD ||| DirectiveLocation.INLINE_FRAGMENT
Args =
[| { InputFieldDefinition.Name = "if"
Description = Some "Included when true."
IsSkippable = false
TypeDef = BooleanType
DefaultValue = None
ExecuteInput = variableOrElse (InlineConstant >> coerceBoolInput >> Result.map box) } |] }
/// GraphQL @skip directive.
let SkipDirective : DirectiveDef =
{ Name = "skip"
Description = Some "Directs the executor to skip this field or fragment when the `if` argument is true."
Locations =
DirectiveLocation.FIELD ||| DirectiveLocation.FRAGMENT_SPREAD ||| DirectiveLocation.INLINE_FRAGMENT
Args =
[| { InputFieldDefinition.Name = "if"
Description = Some "Skipped when true."
IsSkippable = false
TypeDef = BooleanType
DefaultValue = None
ExecuteInput = variableOrElse (InlineConstant >> coerceBoolInput >> Result.map box) } |] }
/// GraphQL @defer directive.
let DeferDirective : DirectiveDef =
{ Name = "defer"
Description = Some "Defers the resolution of this field or fragment"
Locations =
DirectiveLocation.FIELD ||| DirectiveLocation.FRAGMENT_SPREAD ||| DirectiveLocation.INLINE_FRAGMENT ||| DirectiveLocation.FRAGMENT_DEFINITION
Args = [||] }
/// GraphQL @stream directive.
let StreamDirective : DirectiveDef =
{ Name = "stream"
Description = Some "Streams the resolution of this field or fragment"
Locations =
DirectiveLocation.FIELD ||| DirectiveLocation.FRAGMENT_SPREAD ||| DirectiveLocation.INLINE_FRAGMENT ||| DirectiveLocation.FRAGMENT_DEFINITION
Args = [||] }
/// GraphQL @live directive.
let LiveDirective : DirectiveDef =
{ Name = "live"
Description = Some "Subscribes for live updates of this field or fragment"
Locations =
DirectiveLocation.FIELD ||| DirectiveLocation.FRAGMENT_SPREAD ||| DirectiveLocation.INLINE_FRAGMENT ||| DirectiveLocation.FRAGMENT_DEFINITION
Args = [||] }
let inline internal strip (fn : 'In -> 'Out) : obj -> obj = fun i -> upcast fn (i :?> 'In)
/// Common space for all definition helper methods.
[<AbstractClass; Sealed>]
type Define =
/// <summary>
/// Creates GraphQL type definition for user defined scalar.
/// </summary>
/// <param name="name">Type name. Must be unique in scope of the current schema.</param>
/// <param name="coerceInput">Function used to resolve .NET object from GraphQL query AST or variable.</param>
/// <param name="coerceOutput">Function used to cross cast to .NET types.</param>
/// <param name="description">Optional scalar description. Usefull for generating documentation.</param>
static member Scalar(name : string, coerceInput : InputParameterValue -> Result<'T, string>,
coerceOutput : obj -> 'T option, ?description : string) : ScalarDefinition<'T> =
{ Name = name
Description = description
CoerceInput = coerceInput >> Result.mapError (fun msg -> { new IGQLError with member _.Message = msg } |> List.singleton)
CoerceOutput = coerceOutput }
/// <summary>
/// Creates GraphQL type definition for user defined scalar.
/// </summary>
/// <param name="name">Type name. Must be unique in scope of the current schema.</param>
/// <param name="coerceInput">Function used to resolve .NET object from GraphQL query AST or variable.</param>
/// <param name="coerceOutput">Function used to cross cast to .NET types.</param>
/// <param name="description">Optional scalar description. Usefull for generating documentation.</param>
static member Scalar(name : string, coerceInput : InputParameterValue -> Result<'T, string list>,
coerceOutput : obj -> 'T option, ?description : string) : ScalarDefinition<'T> =
{ Name = name
Description = description
CoerceInput = coerceInput >> Result.mapError (List.map (fun msg -> { new IGQLError with member _.Message = msg }))
CoerceOutput = coerceOutput }
/// <summary>
/// Creates GraphQL type definition for user defined scalar.
/// </summary>
/// <param name="name">Type name. Must be unique in scope of the current schema.</param>
/// <param name="coerceInput">Function used to resolve .NET object from GraphQL query AST or variable.</param>
/// <param name="coerceOutput">Function used to cross cast to .NET types.</param>
/// <param name="description">Optional scalar description. Usefull for generating documentation.</param>
static member Scalar(name : string, coerceInput : InputParameterValue -> Result<'T, IGQLError>,
coerceOutput : obj -> 'T option, ?description : string) : ScalarDefinition<'T> =
{ Name = name
Description = description
CoerceInput = coerceInput >> Result.mapError List.singleton
CoerceOutput = coerceOutput }
/// <summary>
/// Creates GraphQL type definition for user defined scalar.
/// </summary>
/// <param name="name">Type name. Must be unique in scope of the current schema.</param>
/// <param name="coerceInput">Function used to resolve .NET object from GraphQL query AST or variable.</param>
/// <param name="coerceOutput">Function used to cross cast to .NET types.</param>
/// <param name="description">Optional scalar description. Usefull for generating documentation.</param>
static member Scalar(name : string, coerceInput : InputParameterValue -> Result<'T, IGQLError list>,
coerceOutput : obj -> 'T option, ?description : string) : ScalarDefinition<'T> =
{ Name = name
Description = description
CoerceInput = coerceInput
CoerceOutput = coerceOutput }
/// <summary>
/// Creates GraphQL type definition for user defined wrapped scalar.
/// </summary>
/// <param name="name">Type name. Must be unique in scope of the current schema.</param>
/// <param name="coerceInput">Function used to resolve .NET object from GraphQL query AST or variable.</param>
/// <param name="coerceOutput">Function used to cross cast to .NET types.</param>
/// <param name="description">Optional scalar description. Usefull for generating documentation.</param>
static member WrappedScalar(name : string, coerceInput : InputParameterValue -> Result<'Wrapper, string>,
coerceOutput : obj -> 'Primitive option, ?description : string) : ScalarDefinition<'Primitive, 'Wrapper> =
{ Name = name
Description = description
CoerceInput = coerceInput >> Result.mapError (fun msg -> { new IGQLError with member _.Message = msg } |> List.singleton)
CoerceOutput = coerceOutput }
/// <summary>
/// Creates GraphQL type definition for user defined wrapped scalar.
/// </summary>
/// <param name="name">Type name. Must be unique in scope of the current schema.</param>
/// <param name="coerceInput">Function used to resolve .NET object from GraphQL query AST or variable.</param>
/// <param name="coerceOutput">Function used to cross cast to .NET types.</param>
/// <param name="description">Optional scalar description. Usefull for generating documentation.</param>
static member WrappedScalar(name : string, coerceInput : InputParameterValue -> Result<'Wrapper, string list>,
coerceOutput : obj -> 'Primitive option, ?description : string) : ScalarDefinition<'Primitive, 'Wrapper> =
{ Name = name
Description = description
CoerceInput = coerceInput >> Result.mapError (List.map (fun msg -> { new IGQLError with member _.Message = msg }))
CoerceOutput = coerceOutput }
/// <summary>
/// Creates GraphQL type definition for user defined wrapped scalar.
/// </summary>
/// <param name="name">Type name. Must be unique in scope of the current schema.</param>
/// <param name="coerceInput">Function used to resolve .NET object from GraphQL query AST or variable.</param>
/// <param name="coerceOutput">Function used to cross cast to .NET types.</param>
/// <param name="description">Optional scalar description. Usefull for generating documentation.</param>
static member WrappedScalar(name : string, coerceInput : InputParameterValue -> Result<'Wrapper, IGQLError>,
coerceOutput : obj -> 'Primitive option, ?description : string) : ScalarDefinition<'Primitive, 'Wrapper> =
{ Name = name
Description = description
CoerceInput = coerceInput >> Result.mapError List.singleton
CoerceOutput = coerceOutput }
/// <summary>
/// Creates GraphQL type definition for user defined wrapped scalar.
/// </summary>
/// <param name="name">Type name. Must be unique in scope of the current schema.</param>
/// <param name="coerceInput">Function used to resolve .NET object from GraphQL query AST or variable.</param>
/// <param name="coerceOutput">Function used to cross cast to .NET types.</param>
/// <param name="description">Optional scalar description. Usefull for generating documentation.</param>
static member WrappedScalar(name : string, coerceInput : InputParameterValue -> Result<'Wrapper, IGQLError list>,
coerceOutput : obj -> 'Primitive option, ?description : string) : ScalarDefinition<'Primitive, 'Wrapper> =
{ Name = name
Description = description
CoerceInput = coerceInput
CoerceOutput = coerceOutput }
/// <summary>
/// Creates GraphQL type definition for user defined enums.
/// </summary>
/// <param name="name">Type name. Must be unique in scope of the current schema.</param>
/// <param name="options">List of enum value cases.</param>
/// <param name="description">Optional enum description. Usefull for generating documentation.</param>
static member Enum(name : string, options : EnumValue<'Val> list, ?description : string) : EnumDef<'Val> =
upcast { EnumDefinition.Name = name
Description = description
Options = options |> List.toArray }
/// <summary>
/// Creates a single enum option to be used as argument in <see cref="Schema.Enum"/>.
/// </summary>
/// <param name="name">Enum value name. Must be unique in scope of the defining enum.</param>
/// <param name="value">
/// .NET value associated with target enum value. All enum values are represented as strings in GraphQL type system.
/// Enum value will be stringified using 'ToString()' method when passing to a client.
/// </param>
/// <param name="description">Optional enum value description. Usefull for generating documentation.</param>
/// <param name="deprecationReason">If set, marks an enum value as deprecated.</param>
static member EnumValue(name : string, value : 'Val, ?description : string, ?deprecationReason : string) : EnumValue<'Val> =
{ Name = name
Description = description
Value = value
DeprecationReason = deprecationReason }
/// <summary>
/// Creates GraphQL custom output object type. It can be used as a valid output but not an input object
/// (see <see cref="InputObject"/> for more details).
/// </summary>
/// <param name="name">Type name. Must be unique in scope of the current schema.</param>
/// <param name="fields">List of fields defined by the current object. </param>
/// <param name="description">Optional object description. Usefull for generating documentation.</param>
/// <param name="interfaces">
/// List of implemented interfaces. Object must explicitly define all fields from all interfaces it implements.
/// </param>
/// <param name="isTypeOf">
/// Optional function used to determine if provided .NET object instance matches current object definition.
/// </param>
static member Object(name : string, fields : FieldDef<'Val> list, ?description : string,
?interfaces : InterfaceDef list, ?isTypeOf : obj -> bool) : ObjectDef<'Val> =
upcast { ObjectDefinition.Name = name
Description = description
FieldsFn =
lazy (fields
|> List.map (fun f -> f.Name, f)
|> Map.ofList)
Implements = defaultArg (Option.map List.toArray interfaces) [||]
IsTypeOf = isTypeOf }
/// <summary>
/// Creates a custom GraphQL input object type. Unlike GraphQL objects, input objects are valid input types,
/// that can be included in GraphQL query strings. Input object maps to a .NET type, which can be standard
/// .NET class or struct, or a F# record.
/// </summary>
/// <param name="name">Type name. Must be unique in scope of the current schema.</param>
/// <param name="fields">List of input fields defined by the current input object. </param>
/// <param name="description">Optional input object description. Useful for generating documentation.</param>
static member InputObject(name : string, fields : InputFieldDef list, ?description : string) : InputObjectDefinition<'Out> =
{ Name = name
Description = description
Fields = lazy (fields |> List.toArray)
Validator = GQLValidator.empty
ExecuteInput = Unchecked.defaultof<_> }
/// <summary>
/// Creates a custom GraphQL input object type. Unlike GraphQL objects, input objects are valid input types,
/// that can be included in GraphQL query strings. Input object maps to a .NET type, which can be standard
/// .NET class or struct, or a F# record.
/// </summary>
/// <param name="name">Type name. Must be unique in scope of the current schema.</param>
/// <param name="fields">List of input fields defined by the current input object. </param>
/// <param name="description">Optional input object description. Useful for generating documentation.</param>
static member InputObject(name : string, fields : InputFieldDef list, validator: GQLValidator<'Out>, ?description : string) : InputObjectDefinition<'Out> =
{ Name = name
Description = description
Fields = lazy (fields |> List.toArray)
Validator = validator
ExecuteInput = Unchecked.defaultof<_> }
/// <summary>
/// Creates the top level subscription object that holds all of the possible subscriptions as fields.
/// </summary>
/// <param name="name">Top level name. Must be unique in scope of the current schema.</param>
/// <param name="fields">List of subscription fields to be defined for the schema. </param>
/// <param name="description">Optional description. Usefull for generating documentation.</param>
static member SubscriptionObject<'Val>(name: string, fields: SubscriptionFieldDef<'Val> list, ?description: string):SubscriptionObjectDefinition<'Val> =
{ Name = name
Fields = (fields |> List.map (fun f -> f.Name, f) |> Map.ofList)
Description = description }
/// <summary>
/// Creates field defined inside object types with automatically generated field resolve function.
/// Field name must match object's property or field.
/// </summary>
/// <param name="name">Field name. Must be unique in scope of the defining object.</param>
/// <param name="typedef">GraphQL type definition of the current field's type.</param>
/// <param name="description">Optional field description. Usefull for generating documentation.</param>
/// <param name="args">Optional list of arguments used to parametrize field resolution.</param>
/// <param name="deprecationReason">If set, marks current field as deprecated.</param>
static member AutoField(name : string, typedef : #OutputDef<'Res>, ?description: string, ?args: InputFieldDef list, ?deprecationReason: string) : FieldDef<'Val, 'Res> =
upcast { FieldDefinition.Name = name
Description = description
TypeDef = typedef
Resolve = Resolve.defaultResolve<'Val, 'Res> name
Args = defaultArg args [] |> Array.ofList
DeprecationReason = deprecationReason
Metadata = Metadata.Empty }
/// <summary>
/// Creates field defined inside interfaces. When used for objects may cause runtime exceptions due to
/// lack of resolve function supplied. To use auto generated resolvers use <see cref="AutoField"/>.
/// </summary>
/// <param name="name">Field name. Must be unique in scope of the defining object.</param>
/// <param name="typedef">GraphQL type definition of the current field's type.</param>
/// <param name="deprecationReason">Deprecation reason.</param>
static member Field(name : string, typedef : #OutputDef<'Res>, ?deprecationReason : string) : FieldDef<'Val, 'Res> =
upcast { FieldDefinition.Name = name
Description = None
TypeDef = typedef
Resolve = Undefined
Args = [||]
DeprecationReason = deprecationReason
Metadata = Metadata.Empty }
/// <summary>
/// Creates field defined inside object type.
/// </summary>
/// <param name="name">Field name. Must be unique in scope of the defining object.</param>
/// <param name="typedef">GraphQL type definition of the current field's type.</param>
/// <param name="resolve">Expression used to resolve value from defining object.</param>
/// <param name="deprecationReason">Deprecation reason.</param>
static member Field(name : string, typedef : #OutputDef<'Res>,
[<ReflectedDefinition(true)>] resolve : Expr<ResolveFieldContext -> 'Val -> 'Res>,
?deprecationReason : string) : FieldDef<'Val, 'Res> =
upcast { FieldDefinition.Name = name
Description = None
TypeDef = typedef
Resolve = Sync(typeof<'Val>, typeof<'Res>, resolve)
Args = [||]
DeprecationReason = deprecationReason
Metadata = Metadata.Empty }
/// <summary>
/// Creates field defined inside object type.
/// </summary>
/// <param name="name">Field name. Must be unique in scope of the defining object.</param>
/// <param name="typedef">GraphQL type definition of the current field's type.</param>
/// <param name="description">Optional field description. Usefull for generating documentation.</param>
/// <param name="resolve">Expression used to resolve value from defining object.</param>
/// <param name="deprecationReason">Deprecation reason.</param>
static member Field(name : string, typedef : #OutputDef<'Res>, description : string,
[<ReflectedDefinition(true)>] resolve : Expr<ResolveFieldContext -> 'Val -> 'Res>,
?deprecationReason : string) : FieldDef<'Val, 'Res> =
upcast { FieldDefinition.Name = name
Description = Some description
TypeDef = typedef
Resolve = Sync(typeof<'Val>, typeof<'Res>, resolve)
Args = [||]
DeprecationReason = deprecationReason
Metadata = Metadata.Empty }
/// <summary>
/// Creates field defined inside object type.
/// </summary>
/// <param name="name">Field name. Must be unique in scope of the defining object.</param>
/// <param name="typedef">GraphQL type definition of the current field's type.</param>
/// <param name="args">List of field arguments used to parametrize resolve expression output.</param>
/// <param name="resolve">Expression used to resolve value from defining object.</param>
/// <param name="deprecationReason">Deprecation reason.</param>
static member Field(name : string, typedef : #OutputDef<'Res>, args : InputFieldDef list,
[<ReflectedDefinition(true)>] resolve : Expr<ResolveFieldContext -> 'Val -> 'Res>,
?deprecationReason : string) : FieldDef<'Val, 'Res> =
upcast { FieldDefinition.Name = name
Description = None
TypeDef = typedef
Resolve = Sync(typeof<'Val>, typeof<'Res>, resolve)
Args = args |> List.toArray
DeprecationReason = deprecationReason
Metadata = Metadata.Empty }
/// <summary>
/// Creates field defined inside object type.
/// </summary>
/// <param name="name">Field name. Must be unique in scope of the defining object.</param>
/// <param name="typedef">GraphQL type definition of the current field's type.</param>
/// <param name="description">Optional field description. Usefull for generating documentation.</param>
/// <param name="args">List of field arguments used to parametrize resolve expression output.</param>
/// <param name="resolve">Expression used to resolve value from defining object.</param>
static member Field(name : string, typedef : #OutputDef<'Res>, description : string, args : InputFieldDef list,
[<ReflectedDefinition(true)>] resolve : Expr<ResolveFieldContext -> 'Val -> 'Res>,
?deprecationReason : string) : FieldDef<'Val, 'Res> =
upcast { FieldDefinition.Name = name
Description = Some description
TypeDef = typedef
Resolve = Sync(typeof<'Val>, typeof<'Res>, resolve)
Args = args |> List.toArray
DeprecationReason = deprecationReason
Metadata = Metadata.Empty }
/// <summary>
/// Creates field defined inside object type with asynchronously resolved value.
/// </summary>
/// <param name="name">Field name. Must be unique in scope of the defining object.</param>
/// <param name="typedef">GraphQL type definition of the current field's type.</param>
/// <param name="resolve">Expression used to resolve value from defining object.</param>
/// <param name="deprecationReason">Deprecation reason.</param>
static member AsyncField(name : string, typedef : #OutputDef<'Res>,
[<ReflectedDefinition(true)>] resolve : Expr<ResolveFieldContext -> 'Val -> Async<'Res>>,
?deprecationReason : string) : FieldDef<'Val, 'Res> =
upcast { FieldDefinition.Name = name
Description = None
TypeDef = typedef
Resolve = Async(typeof<'Val>, typeof<'Res>, resolve)
Args = [||]
DeprecationReason = deprecationReason
Metadata = Metadata.Empty }
/// <summary>
/// Creates field defined inside object type with asynchronously resolved value.
/// </summary>
/// <param name="name">Field name. Must be unique in scope of the defining object.</param>
/// <param name="typedef">GraphQL type definition of the current field's type.</param>
/// <param name="description">Optional field description. Usefull for generating documentation.</param>
/// <param name="resolve">Expression used to resolve value from defining object.</param>
/// <param name="deprecationReason">Deprecation reason.</param>
static member AsyncField(name : string, typedef : #OutputDef<'Res>, description : string,
[<ReflectedDefinition(true)>] resolve : Expr<ResolveFieldContext -> 'Val -> Async<'Res>>,
?deprecationReason : string) : FieldDef<'Val, 'Res> =
upcast { FieldDefinition.Name = name
Description = Some description
TypeDef = typedef
Resolve = Async(typeof<'Val>, typeof<'Res>, resolve)
Args = [||]
DeprecationReason = deprecationReason
Metadata = Metadata.Empty }
/// <summary>
/// Creates field defined inside object type with asynchronously resolved value.
/// </summary>
/// <param name="name">Field name. Must be unique in scope of the defining object.</param>
/// <param name="typedef">GraphQL type definition of the current field's type.</param>
/// <param name="args">List of field arguments used to parametrize resolve expression output.</param>
/// <param name="resolve">Expression used to resolve value from defining object.</param>
/// <param name="deprecationReason">Deprecation reason.</param>
static member AsyncField(name : string, typedef : #OutputDef<'Res>, args : InputFieldDef list,
[<ReflectedDefinition(true)>] resolve : Expr<ResolveFieldContext -> 'Val -> Async<'Res>>,
?deprecationReason : string) : FieldDef<'Val, 'Res> =
upcast { FieldDefinition.Name = name
Description = None
TypeDef = typedef
Resolve = Async(typeof<'Val>, typeof<'Res>, resolve)
Args = args |> List.toArray
DeprecationReason = deprecationReason
Metadata = Metadata.Empty }
/// <summary>
/// Creates field defined inside object type with asynchronously resolved value. Fields is marked as deprecated.
/// </summary>
/// <param name="name">Field name. Must be unique in scope of the defining object.</param>
/// <param name="typedef">GraphQL type definition of the current field's type.</param>
/// <param name="description">Optional field description. Usefull for generating documentation.</param>
/// <param name="args">List of field arguments used to parametrize resolve expression output.</param>
/// <param name="resolve">Expression used to resolve value from defining object.</param>
/// <param name="deprecationReason">Deprecation reason.</param>
static member AsyncField(name : string, typedef : #OutputDef<'Res>, description : string,
args : InputFieldDef list,
[<ReflectedDefinition(true)>] resolve : Expr<ResolveFieldContext -> 'Val -> Async<'Res>>,
?deprecationReason : string) : FieldDef<'Val, 'Res> =
upcast { FieldDefinition.Name = name
Description = Some description
TypeDef = typedef
Resolve = Async(typeof<'Val>, typeof<'Res>, resolve)
Args = args |> List.toArray
DeprecationReason = deprecationReason
Metadata = Metadata.Empty }
/// <summary>
/// Creates a custom defined field using a custom field execution function.
/// </summary>
/// <param name="name">Field name. Must be unique in scope of the defining object.</param>
/// <param name="execField">Expression used to execute the field.</param>
static member CustomField(name : string, [<ReflectedDefinition(true)>] execField : Expr<ExecuteField>) : FieldDef<'Val, obj> =
upcast { FieldDefinition.Name = name
Description = None
TypeDef = ObjType
Resolve = ResolveExpr(execField)
Args = [||]
DeprecationReason = None
Metadata = Metadata.Empty }
/// <summary>
/// Creates a subscription field inside object type.
/// </summary>
/// <param name="name">Field name. Must be unique in scope of the defining object.</param>
/// <param name="rootdef">GraphQL type definition of the root field's type.</param>
/// <param name="outputdef">GraphQL type definition of the current field's type.</param>
/// <param name="filter">A filter function which decides if the field should be published to clients or not, by returning it as Some or None.</param>
static member SubscriptionField(name: string, rootdef: #OutputDef<'Root>, outputdef: #OutputDef<'Output>,
[<ReflectedDefinition(true)>] filter: Expr<ResolveFieldContext -> 'Root -> 'Input -> 'Output option>): SubscriptionFieldDef<'Root, 'Input, 'Output> =
upcast { Name = name
Description = None
RootTypeDef = rootdef
OutputTypeDef = outputdef
DeprecationReason = None
Args = [||]
Filter = Resolve.Filter(typeof<'Root>, typeof<'Input>, typeof<'Output>, filter)
Metadata = Metadata.Empty
TagsResolver = fun _ -> Seq.empty }
/// <summary>
/// Creates a subscription field inside object type.
/// </summary>
/// <param name="name">Field name. Must be unique in scope of the defining object.</param>
/// <param name="rootdef">GraphQL type definition of the root field's type.</param>
/// <param name="outputdef">GraphQL type definition of the current field's type.</param>
/// <param name="filter">A filter function which decides if the field should be published to clients or not, by returning it as Some or None.</param>
/// <param name="tagsResolver">A function that resolves subscription tags, used to choose which filter functions will be used when publishing to subscribers.</param>
static member SubscriptionField(name: string, rootdef: #OutputDef<'Root>, outputdef: #OutputDef<'Output>,
[<ReflectedDefinition(true)>] filter: Expr<ResolveFieldContext -> 'Root -> 'Input -> 'Output option>,
tagsResolver : TagsResolver): SubscriptionFieldDef<'Root, 'Input, 'Output> =
upcast { Name = name
Description = None
RootTypeDef = rootdef
OutputTypeDef = outputdef
DeprecationReason = None
Args = [||]
Filter = Resolve.Filter(typeof<'Root>, typeof<'Input>, typeof<'Output>, filter)
Metadata = Metadata.Empty
TagsResolver = tagsResolver }
/// <summary>
/// Creates a subscription field inside object type.
/// </summary>
/// <param name="name">Field name. Must be unique in scope of the defining object.</param>
/// <param name="rootdef">GraphQL type definition of the root field's type.</param>
/// <param name="outputdef">GraphQL type definition of the current field's type.</param>
/// <param name="description">Optional field description. Usefull for generating documentation.</param>
/// <param name="filter">A filter function which decides if the field should be published to clients or not, by returning it as Some or None.</param>
static member SubscriptionField(name: string, rootdef: #OutputDef<'Root>, outputdef: #OutputDef<'Output>,
description: string,
[<ReflectedDefinition(true)>] filter: Expr<ResolveFieldContext -> 'Root -> 'Input -> 'Output option>): SubscriptionFieldDef<'Root, 'Input, 'Output> =
upcast { Name = name
Description = Some description
RootTypeDef = rootdef
OutputTypeDef = outputdef
DeprecationReason = None
Args = [||]
Filter = Resolve.Filter(typeof<'Root>, typeof<'Input>, typeof<'Output>, filter)
Metadata = Metadata.Empty
TagsResolver = fun _ -> Seq.empty }