-
Notifications
You must be signed in to change notification settings - Fork 41
Expand file tree
/
Copy pathParserTests.cs
More file actions
1704 lines (1503 loc) · 67.2 KB
/
ParserTests.cs
File metadata and controls
1704 lines (1503 loc) · 67.2 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
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
using System.Collections;
using System.Runtime.InteropServices;
namespace GraphQLParser.Tests;
public class ParserTests
{
[Fact]
public void GraphQLDocument_Source_ShouldBe_Original_String()
{
string text = "scalar JSON";
var doc = text.Parse();
(doc.Source == text).ShouldBeTrue();
// just to demonstrate how TryGetString works
MemoryMarshal.TryGetString(doc.Source, out var str1, out var start1, out var length1).ShouldBeTrue();
ReferenceEquals(text, str1).ShouldBeTrue();
start1.ShouldBe(0);
length1.ShouldBe(11);
var text2 = text.AsMemory().Slice(1);
MemoryMarshal.TryGetString(text2, out var str2, out var start2, out var length2).ShouldBeTrue();
ReferenceEquals(text, str2).ShouldBeTrue();
start2.ShouldBe(1);
length2.ShouldBe(10);
var text3 = text.AsMemory().Slice(2, 4);
MemoryMarshal.TryGetString(text3, out var str3, out var start3, out var length3).ShouldBeTrue();
ReferenceEquals(text, str3).ShouldBeTrue();
start3.ShouldBe(2);
length3.ShouldBe(4);
}
[Theory]
[InlineData(IgnoreOptions.None)]
//[InlineData(IgnoreOptions.Comments)]
[InlineData(IgnoreOptions.Locations)]
//[InlineData(IgnoreOptions.All)]
public void Extra_Comments_Should_Read_Correctly(IgnoreOptions options)
{
string query = "ExtraComments".ReadGraphQLFile();
var document = query.Parse(new ParserOptions { Ignore = options });
document.Definitions.Count.ShouldBe(1);
// query
var def = document.Definitions.First() as GraphQLOperationDefinition;
def.SelectionSet.Selections.Count.ShouldBe(2);
// person
var field = def.SelectionSet.Selections.First() as GraphQLField;
field.SelectionSet.Selections.Count.ShouldBe(1);
// name
var subField = field.SelectionSet.Selections.First() as GraphQLField;
subField.Comment.ShouldBeNull();
// test
field = def.SelectionSet.Selections.Last() as GraphQLField;
field.SelectionSet.Selections.Count.ShouldBe(1);
field.Comment.ShouldNotBeNull().Value.ShouldBe("comment2");
// alt
subField = field.SelectionSet.Selections.First() as GraphQLField;
subField.Comment.ShouldBeNull();
// extra document comments
document.UnattachedComments.Count.ShouldBe(3);
document.UnattachedComments[0][0].Value.ShouldBe("comment1");
document.UnattachedComments[1][0].Value.ShouldBe("comment3");
document.UnattachedComments[2][0].Value.ShouldBe("comment4");
}
[Theory]
//[InlineData(IgnoreOptions.None)]
[InlineData(IgnoreOptions.Comments)]
//[InlineData(IgnoreOptions.Locations)]
[InlineData(IgnoreOptions.All)]
public void Comments_Can_Be_Ignored(IgnoreOptions options)
{
const string query = @"
{
#comment
person
# comment2
}";
var document = query.Parse(new ParserOptions { Ignore = options });
document.UnattachedComments.ShouldBeNull();
document.Definitions.Count.ShouldBe(1);
var def = document.Definitions.First() as GraphQLOperationDefinition;
def.SelectionSet.Selections.Count.ShouldBe(1);
def.Comment.ShouldBeNull();
var field = def.SelectionSet.Selections.First() as GraphQLField;
field.Comment.ShouldBeNull();
}
[Theory]
[InlineData(IgnoreOptions.None)]
//[InlineData(IgnoreOptions.Comments)]
[InlineData(IgnoreOptions.Locations)]
//[InlineData(IgnoreOptions.All)]
public void Comments_on_FragmentSpread_Should_Read_Correctly(IgnoreOptions options)
{
string query = "CommentsOnFragmentSpread".ReadGraphQLFile();
var document = query.Parse(new ParserOptions { Ignore = options });
document.Definitions.Count.ShouldBe(2);
var def = document.Definitions.First() as GraphQLOperationDefinition;
def.SelectionSet.Selections.Count.ShouldBe(1);
var field = def.SelectionSet.Selections.First() as GraphQLField;
field.SelectionSet.Selections.Count.ShouldBe(1);
var spread = field.SelectionSet.Selections.First() as GraphQLFragmentSpread;
spread.Comment.ShouldNotBeNull().Value.ShouldBe("comment");
spread.FragmentName.Comment.Value.ShouldBe("comment on fragment name 1");
var frag = document.Definitions.Last() as GraphQLFragmentDefinition;
frag.Comment.ShouldBeNull();
frag.FragmentName.Comment.Value.ShouldBe("comment on fragment name 2");
}
[Theory]
[InlineData(IgnoreOptions.None)]
//[InlineData(IgnoreOptions.Comments)]
[InlineData(IgnoreOptions.Locations)]
//[InlineData(IgnoreOptions.All)]
public void Comments_on_Values_Should_Read_Correctly(IgnoreOptions options)
{
string query = "CommentsOnValues".ReadGraphQLFile();
var document = query.Parse(new ParserOptions { Ignore = options });
document.Definitions.Count.ShouldBe(1);
var def = document.Definitions.First() as GraphQLOperationDefinition;
def.SelectionSet.Selections.Count.ShouldBe(1);
var field = def.SelectionSet.Selections.First() as GraphQLField;
field.SelectionSet.Selections.Count.ShouldBe(1);
field.Arguments.Count.ShouldBe(9);
var boolValue = field.Arguments[0].Value.ShouldBeAssignableTo<GraphQLBooleanValue>();
boolValue.Comment.ShouldNotBeNull().Value.ShouldBe("comment for bool");
var nullValue = field.Arguments[1].Value.ShouldBeAssignableTo<GraphQLNullValue>();
nullValue.Comment.ShouldNotBeNull().Value.ShouldBe("comment for null");
var enumValue = field.Arguments[2].Value.ShouldBeAssignableTo<GraphQLEnumValue>();
enumValue.Comment.ShouldNotBeNull().Value.ShouldBe("comment for enum");
var listValue = field.Arguments[3].Value.ShouldBeAssignableTo<GraphQLListValue>();
listValue.Comment.ShouldNotBeNull().Value.ShouldBe("comment for list");
var objValue = field.Arguments[4].Value.ShouldBeAssignableTo<GraphQLObjectValue>();
objValue.Comment.ShouldNotBeNull().Value.ShouldBe("comment for object");
var intValue = field.Arguments[5].Value.ShouldBeAssignableTo<GraphQLIntValue>();
intValue.Comment.ShouldNotBeNull().Value.ShouldBe("comment for int");
var floatValue = field.Arguments[6].Value.ShouldBeAssignableTo<GraphQLFloatValue>();
floatValue.Comment.ShouldNotBeNull().Value.ShouldBe("comment for float");
var stringValue = field.Arguments[7].Value.ShouldBeAssignableTo<GraphQLStringValue>();
stringValue.Comment.ShouldNotBeNull().Value.ShouldBe("comment for string");
var varValue = field.Arguments[8].Value.ShouldBeAssignableTo<GraphQLVariable>();
varValue.Comment.ShouldNotBeNull().Value.ShouldBe("comment for variable");
}
[Theory]
[InlineData(IgnoreOptions.None)]
//[InlineData(IgnoreOptions.Comments)]
[InlineData(IgnoreOptions.Locations)]
//[InlineData(IgnoreOptions.All)]
public void Comments_on_FragmentInline_Should_Read_Correctly(IgnoreOptions options)
{
string query = "CommentsOnInlineFragment".ReadGraphQLFile();
var document = query.Parse(new ParserOptions { Ignore = options });
document.Definitions.Count.ShouldBe(1);
var def = document.Definitions.First() as GraphQLOperationDefinition;
def.SelectionSet.Selections.Count.ShouldBe(1);
var field = def.SelectionSet.Selections.First() as GraphQLField;
field.SelectionSet.Selections.Count.ShouldBe(1);
var fragment = field.SelectionSet.Selections.First() as GraphQLInlineFragment;
fragment.Comment.ShouldNotBeNull().Value.ShouldBe("comment");
}
[Theory]
[InlineData(IgnoreOptions.None)]
//[InlineData(IgnoreOptions.Comments)]
[InlineData(IgnoreOptions.Locations)]
//[InlineData(IgnoreOptions.All)]
public void Comments_on_Arguments_Should_Read_Correctly(IgnoreOptions options)
{
string query = "CommentsOnArguments".ReadGraphQLFile();
var document = query.Parse(new ParserOptions { Ignore = options });
document.Definitions.Count.ShouldBe(1);
var def = document.Definitions[0] as GraphQLOperationDefinition;
def.SelectionSet.Selections.Count.ShouldBe(1);
var field = def.SelectionSet.Selections.First() as GraphQLField;
field.Arguments.Count.ShouldBe(2);
field.Arguments.Comment.ShouldNotBeNull().Value.ShouldBe("arguments comment");
var obj = field.Arguments[1].Value.ShouldBeAssignableTo<GraphQLObjectValue>();
obj.Fields.Count.ShouldBe(1);
obj.Fields[0].Name.Value.ShouldBe("z");
obj.Fields[0].Comment.Value.ShouldBe("comment on object field");
}
[Theory]
[InlineData(IgnoreOptions.None)]
//[InlineData(IgnoreOptions.Comments)]
[InlineData(IgnoreOptions.Locations)]
//[InlineData(IgnoreOptions.All)]
public void Comments_on_NamedTypes_Should_Read_Correctly(IgnoreOptions options)
{
string query = "CommentsOnNamedType".ReadGraphQLFile();
var document = query.Parse(new ParserOptions { Ignore = options });
document.Definitions.Count.ShouldBe(5);
var def1 = document.Definitions[0] as GraphQLOperationDefinition;
var field = def1.SelectionSet.Selections[0] as GraphQLField;
var frag = field.SelectionSet.Selections[0] as GraphQLInlineFragment;
frag.TypeCondition.Type.Comment.Value.ShouldBe("comment for named type from TypeCondition");
var def2 = document.Definitions[1] as GraphQLObjectTypeDefinition;
def2.Interfaces[0].Comment.Value.ShouldBe("comment for named type from ImplementsInterfaces");
var def3 = document.Definitions[2] as GraphQLSchemaDefinition;
def3.OperationTypes[0].Type.Comment.Value.ShouldBe("comment for named type from RootOperationTypeDefinition");
var def4 = document.Definitions[3] as GraphQLObjectTypeDefinition;
def4.Fields[0].Type.Comment.Value.ShouldBe("comment for named type from Type");
var def5 = document.Definitions[4] as GraphQLUnionTypeDefinition;
def5.Types[1].Comment.Value.ShouldBe("comment for named type from UnionMemberTypes");
}
[Theory]
[InlineData(IgnoreOptions.None)]
//[InlineData(IgnoreOptions.Comments)]
[InlineData(IgnoreOptions.Locations)]
//[InlineData(IgnoreOptions.All)]
public void Comments_on_SelectionSet_Should_Read_Correctly(IgnoreOptions options)
{
string query = "CommentsOnSelectionSet".ReadGraphQLFile();
var document = query.Parse(new ParserOptions { Ignore = options });
document.Definitions.Count.ShouldBe(1);
var def = document.Definitions[0] as GraphQLOperationDefinition;
def.SelectionSet.Comment.Value.ShouldBe("comment on selection set");
}
[Theory]
[InlineData(IgnoreOptions.None)]
//[InlineData(IgnoreOptions.Comments)]
[InlineData(IgnoreOptions.Locations)]
//[InlineData(IgnoreOptions.All)]
public void Comments_on_RootOperationType_Should_Read_Correctly(IgnoreOptions options)
{
string query = "CommentsOnRootOperationType".ReadGraphQLFile();
var document = query.Parse(new ParserOptions { Ignore = options });
document.Definitions.Count.ShouldBe(1);
var def = document.Definitions[0] as GraphQLSchemaDefinition;
def.OperationTypes[0].Comment.Value.ShouldBe("comment for root operation type");
}
[Theory]
[InlineData(IgnoreOptions.None)]
//[InlineData(IgnoreOptions.Comments)]
[InlineData(IgnoreOptions.Locations)]
//[InlineData(IgnoreOptions.All)]
public void Comments_on_Directive_Should_Read_Correctly(IgnoreOptions options)
{
string query = "CommentsOnDirective".ReadGraphQLFile();
var document = query.Parse(new ParserOptions { Ignore = options });
document.Definitions.Count.ShouldBe(1);
var def = document.Definitions[0] as GraphQLScalarTypeDefinition;
def.Directives[0].Comment.Value.ShouldBe("comment for directive");
}
[Theory]
[InlineData(IgnoreOptions.None)]
//[InlineData(IgnoreOptions.Comments)]
[InlineData(IgnoreOptions.Locations)]
//[InlineData(IgnoreOptions.All)]
public void Comments_on_Type_Should_Read_Correctly(IgnoreOptions options)
{
string query = "CommentsOnType".ReadGraphQLFile();
var document = query.Parse(new ParserOptions { Ignore = options });
document.Definitions.Count.ShouldBe(3);
var def = document.Definitions[0] as GraphQLObjectTypeDefinition;
def.Comment.Value.ShouldBe("very good type");
def.Interfaces.Comment.Value.ShouldBe("comment for implemented interfaces");
def.Fields.Comment.Value.ShouldBe("comment for fields definition");
def.Fields[0].Type.Comment.Value.ShouldBe("comment for named type");
def.Fields[0].Arguments.Comment.Value.ShouldBe("comment for arguments definition");
def.Fields[1].Type.Comment.Value.ShouldBe("comment for nonnull type");
def.Fields[2].Type.Comment.Value.ShouldBe("comment for list type");
(def.Fields[2].Type as GraphQLListType).Type.Comment.Value.ShouldBe("comment for item type");
var ext1 = document.Definitions[1] as GraphQLObjectTypeExtension;
ext1.Comment.Value.ShouldBe("forgot about address!");
var ext2 = document.Definitions[2] as GraphQLInterfaceTypeExtension;
ext2.Comment.Value.ShouldBe("forgot about vip!");
}
[Theory]
[InlineData(IgnoreOptions.None)]
//[InlineData(IgnoreOptions.Comments)]
[InlineData(IgnoreOptions.Locations)]
//[InlineData(IgnoreOptions.All)]
public void Comments_on_Input_Should_Read_Correctly(IgnoreOptions options)
{
string query = "CommentsOnInput".ReadGraphQLFile();
var document = query.Parse(new ParserOptions { Ignore = options });
document.Definitions.Count.ShouldBe(2);
var def = document.Definitions[0] as GraphQLInputObjectTypeDefinition;
def.Comment.Value.ShouldBe("very good input");
def.Fields.Comment.Value.ShouldBe("comment for input fields definition");
def.Fields[0].Type.Comment.Value.ShouldBe("comment for named type");
def.Fields[1].Type.Comment.Value.ShouldBe("comment for nonnull type");
def.Fields[2].Type.Comment.Value.ShouldBe("comment for list type");
(def.Fields[2].Type as GraphQLListType).Type.Comment.Value.ShouldBe("comment for item type");
var ext = document.Definitions[1] as GraphQLInputObjectTypeExtension;
ext.Comment.Value.ShouldBe("forgot about address!");
}
[Theory]
[InlineData(IgnoreOptions.None)]
//[InlineData(IgnoreOptions.Comments)]
[InlineData(IgnoreOptions.Locations)]
//[InlineData(IgnoreOptions.All)]
public void Comments_on_Alias_Should_Read_Correctly(IgnoreOptions options)
{
string query = "CommentsOnAlias".ReadGraphQLFile();
var document = query.Parse(new ParserOptions { Ignore = options });
document.Definitions.Count.ShouldBe(1);
var def = document.Definitions[0] as GraphQLOperationDefinition;
def.SelectionSet.Selections.Count.ShouldBe(1);
var field = def.SelectionSet.Selections[0].ShouldBeAssignableTo<GraphQLField>();
field.Comment.Value.ShouldBe("field comment! not alias!");
field.Alias.Name.Value.ShouldBe("a");
field.Alias.Comment.ShouldBeNull();
field.Name.Value.ShouldBe("name");
field.Name.Comment.Value.ShouldBe("field name (GraphQLName) comment");
document.UnattachedComments.Count.ShouldBe(1);
document.UnattachedComments[0][0].Value.ShouldBe("colon comment");
}
[Theory]
[InlineData(IgnoreOptions.None)]
//[InlineData(IgnoreOptions.Comments)]
[InlineData(IgnoreOptions.Locations)]
//[InlineData(IgnoreOptions.All)]
public void Comments_on_DirectiveDefinition_Should_Read_Correctly(IgnoreOptions options)
{
string query = "CommentsOnDirectiveDefinition".ReadGraphQLFile();
var document = query.Parse(new ParserOptions { Ignore = options });
document.Definitions.Count.ShouldBe(1);
var def = document.Definitions[0] as GraphQLDirectiveDefinition;
def.Comment.Value.ShouldBe("very good directive");
def.Locations.Comment.Value.ShouldBe("comment for directive locations");
document.UnattachedComments.ShouldBeNull();
}
[Theory]
[InlineData(IgnoreOptions.None)]
//[InlineData(IgnoreOptions.Comments)]
[InlineData(IgnoreOptions.Locations)]
//[InlineData(IgnoreOptions.All)]
public void Comments_on_Enum_Should_Read_Correctly(IgnoreOptions options)
{
string query = "CommentsOnEnum".ReadGraphQLFile();
var document = query.Parse(new ParserOptions { Ignore = options });
document.Definitions.Count.ShouldBe(2);
document.OperationWithName("qwerty").ShouldBeNull();
document.OperationWithName("").ShouldBeNull();
var def = document.Definitions[0] as GraphQLEnumTypeDefinition;
def.Comment.Value.ShouldBe("very good colors");
def.Values.Comment.Value.ShouldBe("values");
def.Values[0].Comment.Value.ShouldBe("not green");
def.Values[1].Comment.Value.ShouldBe("not red");
var ext = document.Definitions[1] as GraphQLEnumTypeExtension;
ext.Comment.Value.ShouldBe("forgot about orange!");
document.UnattachedComments.ShouldBeNull();
}
[Theory]
[InlineData(IgnoreOptions.None)]
//[InlineData(IgnoreOptions.Comments)]
[InlineData(IgnoreOptions.Locations)]
//[InlineData(IgnoreOptions.All)]
public void Comments_on_Schema_Should_Read_Correctly(IgnoreOptions options)
{
string query = "CommentsOnSchema".ReadGraphQLFile();
var document = query.Parse(new ParserOptions { Ignore = options });
document.Definitions.Count.ShouldBe(2);
var def = document.Definitions[0] as GraphQLSchemaDefinition;
def.Comment.Value.ShouldBe("very good schema");
var ext = document.Definitions[1] as GraphQLSchemaExtension;
ext.Comment.Value.ShouldBe("forgot about mutation!");
document.UnattachedComments.ShouldBeNull();
}
[Theory]
[InlineData(IgnoreOptions.None)]
//[InlineData(IgnoreOptions.Comments)]
[InlineData(IgnoreOptions.Locations)]
//[InlineData(IgnoreOptions.All)]
public void Comments_on_Scalar_Should_Read_Correctly(IgnoreOptions options)
{
string query = "CommentsOnScalar".ReadGraphQLFile();
var document = query.Parse(new ParserOptions { Ignore = options });
document.Definitions.Count.ShouldBe(2);
var def = document.Definitions[0] as GraphQLScalarTypeDefinition;
def.Comment.Value.ShouldBe("very good scalar");
var ext = document.Definitions[1] as GraphQLScalarTypeExtension;
ext.Comment.Value.ShouldBe("forgot about external!");
document.UnattachedComments.ShouldBeNull();
}
[Theory]
[InlineData(IgnoreOptions.None)]
//[InlineData(IgnoreOptions.Comments)]
[InlineData(IgnoreOptions.Locations)]
//[InlineData(IgnoreOptions.All)]
public void Comments_on_Union_Should_Read_Correctly(IgnoreOptions options)
{
string query = "CommentsOnUnion".ReadGraphQLFile();
var document = query.Parse(new ParserOptions { Ignore = options });
document.Definitions.Count.ShouldBe(2);
var def = document.Definitions[0] as GraphQLUnionTypeDefinition;
def.Comment.Value.ShouldBe("very good union");
def.Types.Comment.Value.ShouldBe("comment for union members");
var ext = document.Definitions[1] as GraphQLUnionTypeExtension;
ext.Comment.Value.ShouldBe("forgot about C!");
document.UnattachedComments.ShouldBeNull();
}
[Theory]
[InlineData(IgnoreOptions.None)]
//[InlineData(IgnoreOptions.Comments)]
[InlineData(IgnoreOptions.Locations)]
//[InlineData(IgnoreOptions.All)]
public void Comments_on_Variable_Should_Read_Correctly(IgnoreOptions options)
{
string query = "CommentsOnVariables".ReadGraphQLFile();
var document = query.Parse(new ParserOptions { Ignore = options });
document.Definitions.Count.ShouldBe(1);
var def = document.Definitions.First() as GraphQLOperationDefinition;
def.Variables.Count.ShouldBe(3);
def.Variables.Comment.Value.ShouldBe("very good variables definition");
def.Variables[0].Comment.ShouldNotBeNull().Value.ShouldBe("comment1");
def.Variables.Skip(1).First().Comment.ShouldBeNull();
def.Variables.Skip(2).First().Comment.ShouldNotBeNull().Value.ShouldBe("comment3");
}
[Theory]
[InlineData(IgnoreOptions.None)]
//[InlineData(IgnoreOptions.Comments)]
[InlineData(IgnoreOptions.Locations)]
//[InlineData(IgnoreOptions.All)]
public void Comments_On_SelectionSet_Should_Read_Correctly(IgnoreOptions options)
{
var document = @"
query {
# a comment below query
field1
field2
#second comment
field3
}
".Parse(new ParserOptions { Ignore = options });
document.Definitions.Count.ShouldBe(1);
var def = document.Definitions.First() as GraphQLOperationDefinition;
def.SelectionSet.Selections.Count.ShouldBe(3);
def.SelectionSet.Selections.First().Comment.ShouldNotBeNull().Value.ShouldBe(" a comment below query");
def.SelectionSet.Selections.Skip(1).First().Comment.ShouldBe(null);
def.SelectionSet.Selections.Skip(2).First().Comment.ShouldNotBeNull().Value.ShouldBe("second comment");
}
[Theory]
[InlineData(IgnoreOptions.None)]
//[InlineData(IgnoreOptions.Comments)]
[InlineData(IgnoreOptions.Locations)]
//[InlineData(IgnoreOptions.All)]
public void Comments_On_Enum_Definitions_Should_Read_Correctly(IgnoreOptions options)
{
var document = @"
# different animals
enum Animal {
#a cat
Cat
#a dog
Dog
Octopus
#bird is the word
Bird
}
input Parameter {
#any value
Value: String
}
scalar JSON
".Parse(new ParserOptions { Ignore = options });
document.Definitions.Count.ShouldBe(3);
var d1 = document.Definitions.First() as GraphQLEnumTypeDefinition;
d1.Name.Value.ShouldBe("Animal");
d1.Comment.ShouldNotBeNull().Value.ShouldBe(" different animals");
d1.Values[0].Name.Value.ShouldBe("Cat");
d1.Values[0].Comment.ShouldNotBeNull();
d1.Values[0].Comment.Value.ShouldBe("a cat");
d1.Values.Skip(2).First().Name.Value.ShouldBe("Octopus");
d1.Values.Skip(2).First().Comment.ShouldBeNull();
var d2 = document.Definitions.Skip(1).First() as GraphQLInputObjectTypeDefinition;
d2.Name.Value.ShouldBe("Parameter");
d2.Comment.ShouldBeNull();
d2.Fields.Count.ShouldBe(1);
d2.Fields[0].Comment.Value.ShouldBe("any value");
}
[Theory]
[InlineData(IgnoreOptions.None)]
[InlineData(IgnoreOptions.Comments)]
//[InlineData(IgnoreOptions.Locations)]
//[InlineData(IgnoreOptions.All)]
public void Parse_FieldInput_HasCorrectLocations(IgnoreOptions options)
{
// { field }
var document = ParseGraphQLFieldSource(options);
document.Location.ShouldBe(new GraphQLLocation(0, 9)); // { field }
document.Definitions.First().Location.ShouldBe(new GraphQLLocation(0, 9)); // { field }
(document.Definitions.First() as GraphQLOperationDefinition).SelectionSet.Location.ShouldBe(new GraphQLLocation(0, 9)); // { field }
(document.Definitions.First() as GraphQLOperationDefinition).SelectionSet.Selections.First().Location.ShouldBe(new GraphQLLocation(2, 7)); // field
}
[Theory]
[InlineData(IgnoreOptions.None)]
[InlineData(IgnoreOptions.Comments)]
[InlineData(IgnoreOptions.Locations)]
[InlineData(IgnoreOptions.All)]
public void Parse_FieldInput_HasOneOperationDefinition(IgnoreOptions options)
{
var document = ParseGraphQLFieldSource(options);
document.Definitions.First().Kind.ShouldBe(ASTNodeKind.OperationDefinition);
}
[Theory]
[InlineData(IgnoreOptions.None)]
[InlineData(IgnoreOptions.Comments)]
[InlineData(IgnoreOptions.Locations)]
[InlineData(IgnoreOptions.All)]
public void Parse_FieldInput_NameIsNull(IgnoreOptions options)
{
var document = ParseGraphQLFieldSource(options);
GetSingleOperationDefinition(document).Name.ShouldBeNull();
}
[Theory]
[InlineData(IgnoreOptions.None)]
[InlineData(IgnoreOptions.Comments)]
[InlineData(IgnoreOptions.Locations)]
[InlineData(IgnoreOptions.All)]
public void Parse_FieldInput_OperationIsQuery(IgnoreOptions options)
{
var document = ParseGraphQLFieldSource(options);
GetSingleOperationDefinition(document).Operation.ShouldBe(OperationType.Query);
}
[Theory]
[InlineData(IgnoreOptions.None)]
[InlineData(IgnoreOptions.Comments)]
[InlineData(IgnoreOptions.Locations)]
[InlineData(IgnoreOptions.All)]
public void Parse_FieldInput_ReturnsDocumentNode(IgnoreOptions options)
{
var document = ParseGraphQLFieldSource(options);
document.Kind.ShouldBe(ASTNodeKind.Document);
}
[Theory]
[InlineData(IgnoreOptions.None)]
[InlineData(IgnoreOptions.Comments)]
[InlineData(IgnoreOptions.Locations)]
[InlineData(IgnoreOptions.All)]
public void Parse_FieldInput_SelectionSetContainsSingleField(IgnoreOptions options)
{
var document = ParseGraphQLFieldSource(options);
GetSingleSelection(document).Kind.ShouldBe(ASTNodeKind.Field);
}
[Theory]
[InlineData(IgnoreOptions.None)]
[InlineData(IgnoreOptions.Comments)]
//[InlineData(IgnoreOptions.Locations)]
//[InlineData(IgnoreOptions.All)]
public void Parse_FieldWithOperationTypeAndNameInput_HasCorrectLocations(IgnoreOptions options)
{
// mutation Foo { field }
var document = ParseGraphQLFieldWithOperationTypeAndNameSource(options);
document.Location.ShouldBe(new GraphQLLocation(0, 22));
document.Definitions.First().Location.ShouldBe(new GraphQLLocation(0, 22));
(document.Definitions.First() as GraphQLOperationDefinition).Name.Location.ShouldBe(new GraphQLLocation(9, 12)); // Foo
(document.Definitions.First() as GraphQLOperationDefinition).SelectionSet.Location.ShouldBe(new GraphQLLocation(13, 22)); // { field }
(document.Definitions.First() as GraphQLOperationDefinition).SelectionSet.Selections.First().Location.ShouldBe(new GraphQLLocation(15, 20)); // field
}
[Theory]
[InlineData(IgnoreOptions.None)]
[InlineData(IgnoreOptions.Comments)]
[InlineData(IgnoreOptions.Locations)]
[InlineData(IgnoreOptions.All)]
public void Parse_FieldWithOperationTypeAndNameInput_HasOneOperationDefinition(IgnoreOptions options)
{
var document = ParseGraphQLFieldWithOperationTypeAndNameSource(options);
document.Definitions.First().Kind.ShouldBe(ASTNodeKind.OperationDefinition);
}
[Theory]
[InlineData(IgnoreOptions.None)]
[InlineData(IgnoreOptions.Comments)]
[InlineData(IgnoreOptions.Locations)]
[InlineData(IgnoreOptions.All)]
public void Parse_FieldWithOperationTypeAndNameInput_NameIsNull(IgnoreOptions options)
{
var document = ParseGraphQLFieldWithOperationTypeAndNameSource(options);
GetSingleOperationDefinition(document).Name.Value.ShouldBe("Foo");
}
[Theory]
[InlineData(IgnoreOptions.None)]
[InlineData(IgnoreOptions.Comments)]
[InlineData(IgnoreOptions.Locations)]
[InlineData(IgnoreOptions.All)]
public void Parse_FieldWithOperationTypeAndNameInput_OperationIsQuery(IgnoreOptions options)
{
var document = ParseGraphQLFieldWithOperationTypeAndNameSource(options);
GetSingleOperationDefinition(document).Operation.ShouldBe(OperationType.Mutation);
}
[Theory]
[InlineData(IgnoreOptions.None)]
[InlineData(IgnoreOptions.Comments)]
[InlineData(IgnoreOptions.Locations)]
[InlineData(IgnoreOptions.All)]
public void Parse_FieldWithOperationTypeAndNameInput_ReturnsDocumentNode(IgnoreOptions options)
{
var document = ParseGraphQLFieldWithOperationTypeAndNameSource(options);
document.Kind.ShouldBe(ASTNodeKind.Document);
}
[Theory]
[InlineData(IgnoreOptions.None)]
[InlineData(IgnoreOptions.Comments)]
[InlineData(IgnoreOptions.Locations)]
[InlineData(IgnoreOptions.All)]
public void Parse_FieldWithOperationTypeAndNameInput_SelectionSetContainsSingleFieldWithOperationTypeAndNameSelection(IgnoreOptions options)
{
var document = ParseGraphQLFieldWithOperationTypeAndNameSource(options);
GetSingleSelection(document).Kind.ShouldBe(ASTNodeKind.Field);
}
[Theory]
[InlineData(IgnoreOptions.None)]
[InlineData(IgnoreOptions.Comments)]
[InlineData(IgnoreOptions.Locations)]
[InlineData(IgnoreOptions.All)]
public void Parse_KitchenSink_DoesNotThrowError(IgnoreOptions options)
{
var document = "KitchenSink".ReadGraphQLFile().Parse(new ParserOptions { Ignore = options });
document.OperationsCount().ShouldBe(5);
document.FragmentsCount().ShouldBe(1);
document.FindFragmentDefinition("qwerty").ShouldBeNull();
document.FindFragmentDefinition("frag").ShouldNotBeNull();
document.OperationWithName("qwerty").ShouldBeNull();
document.OperationWithName("updateStory").ShouldNotBeNull().Name.Value.ShouldBe("updateStory");
document.OperationWithName("").ShouldNotBeNull().Name.Value.ShouldBe("queryName");
var typeDef = document.Definitions.OfType<GraphQLObjectTypeDefinition>().First(d => d.Name.Value == "Foo");
var fieldDef = typeDef.Fields.First(d => d.Name.Value == "three");
if (options.HasFlag(IgnoreOptions.Comments))
{
fieldDef.Comment.ShouldBeNull();
}
else
{
fieldDef.Comments.ShouldNotBeNull();
fieldDef.Comments.Count.ShouldBe(3);
fieldDef.Comments[0].Value.ShouldBe(" multiline comments");
fieldDef.Comments[1].Value.ShouldBe(" with very importand description #");
fieldDef.Comments[2].Value.ShouldBe(" # and symbol # and ##");
}
// Schema description
// https://github.com/graphql/graphql-spec/pull/466
var comments = document.Definitions.OfType<GraphQLSchemaDefinition>().First().Comments;
if (options.HasFlag(IgnoreOptions.Comments))
{
comments.ShouldBeNull();
}
else
{
comments.ShouldNotBeNull();
(comments[0].Value == " Copyright (c) 2015, Facebook, Inc.").ShouldBeTrue();
}
}
[Theory]
[InlineData(IgnoreOptions.None)]
[InlineData(IgnoreOptions.Comments)]
[InlineData(IgnoreOptions.Locations)]
[InlineData(IgnoreOptions.All)]
public void Parse_NullInput_EmptyDocument(IgnoreOptions options)
{
var document = ((string)null).Parse(new ParserOptions { Ignore = options });
document.Definitions.ShouldBeEmpty();
}
[Theory]
[InlineData(IgnoreOptions.None)]
[InlineData(IgnoreOptions.Comments)]
[InlineData(IgnoreOptions.Locations)]
[InlineData(IgnoreOptions.All)]
public void Parse_VariableInlineValues_DoesNotThrowError(IgnoreOptions options)
{
"{ field(complex: { a: { b: [ $var ] } }) }".Parse(new ParserOptions { Ignore = options });
}
[Theory]
[InlineData(IgnoreOptions.None)]
[InlineData(IgnoreOptions.Comments)]
[InlineData(IgnoreOptions.Locations)]
[InlineData(IgnoreOptions.All)]
public void Should_Read_Directives_on_VariableDefinition(IgnoreOptions options)
{
var document = "query A($id: String @a @b(priority: 1, managed: true)) { name }".Parse(new ParserOptions { Ignore = options });
document.Definitions.Count.ShouldBe(1);
var def = document.Definitions[0].ShouldBeAssignableTo<GraphQLOperationDefinition>();
def.Variables.Count.ShouldBe(1);
def.Variables[0].Directives.Count.ShouldBe(2);
def.Variables[0].Directives[0].Name.Value.ShouldBe("a");
def.Variables[0].Directives[1].Name.Value.ShouldBe("b");
def.Variables[0].Directives[1].Arguments.Count.ShouldBe(2);
// ASTListNode small test
def.Variables.GetEnumerator().ShouldBe(((IEnumerable)def.Variables).GetEnumerator());
}
[Theory]
[InlineData(IgnoreOptions.None)]
[InlineData(IgnoreOptions.Comments)]
[InlineData(IgnoreOptions.Locations)]
[InlineData(IgnoreOptions.All)]
public void Should_Read_Directives_on_OperationDefinition(IgnoreOptions options)
{
var document = "query A @easy { name }".Parse(new ParserOptions { Ignore = options });
document.Definitions.Count.ShouldBe(1);
var def = document.Definitions[0].ShouldBeAssignableTo<GraphQLOperationDefinition>();
def.Directives.Count.ShouldBe(1);
def.Directives[0].Name.Value.ShouldBe("easy");
}
[Theory]
[InlineData(IgnoreOptions.None)]
[InlineData(IgnoreOptions.Comments)]
[InlineData(IgnoreOptions.Locations)]
[InlineData(IgnoreOptions.All)]
public void Should_Read_Directives_on_FragmentSpread(IgnoreOptions options)
{
var document = "query { ...spread1 @skip(if: false) }".Parse(new ParserOptions { Ignore = options });
document.Definitions.Count.ShouldBe(1);
var def = document.Definitions[0].ShouldBeAssignableTo<GraphQLOperationDefinition>();
var spread = def.SelectionSet.Selections[0].ShouldBeAssignableTo<GraphQLFragmentSpread>();
spread.Directives.Count.ShouldBe(1);
spread.Directives[0].Name.Value.ShouldBe("skip");
}
[Theory]
[InlineData(IgnoreOptions.None)]
[InlineData(IgnoreOptions.Comments)]
[InlineData(IgnoreOptions.Locations)]
[InlineData(IgnoreOptions.All)]
public void Should_Read_Directives_on_FragmentDefinition(IgnoreOptions options)
{
var document = "fragment f on User @documented { name }".Parse(new ParserOptions { Ignore = options });
document.Definitions.Count.ShouldBe(1);
var def = document.Definitions[0].ShouldBeAssignableTo<GraphQLFragmentDefinition>();
def.Directives.Count.ShouldBe(1);
def.Directives[0].Name.Value.ShouldBe("documented");
}
private static GraphQLOperationDefinition GetSingleOperationDefinition(GraphQLDocument document)
{
return (GraphQLOperationDefinition)document.Definitions.Single();
}
private static ASTNode GetSingleSelection(GraphQLDocument document)
{
return GetSingleOperationDefinition(document).SelectionSet.Selections.Single();
}
private static GraphQLDocument ParseGraphQLFieldSource(IgnoreOptions options) => "{ field }".Parse(new ParserOptions { Ignore = options });
private static GraphQLDocument ParseGraphQLFieldWithOperationTypeAndNameSource(IgnoreOptions options) => "mutation Foo { field }".Parse(new ParserOptions { Ignore = options });
[Theory]
[InlineData("directive @dir repeatable on FIELD_DEFINITION", true)]
[InlineData("directive @dir(a: Int) repeatable on FIELD_DEFINITION", true)]
[InlineData("directive @dir on FIELD_DEFINITION | ENUM_VALUE", false)]
[InlineData("directive @dir on | FIELD_DEFINITION | ENUM_VALUE", false)]
[InlineData(@"directive @dir on
FIELD_DEFINITION | ENUM_VALUE", false)]
[InlineData(@"directive @dir on
FIELD_DEFINITION
| ENUM_VALUE", false)]
[InlineData(@"directive @dir on
| FIELD_DEFINITION
| ENUM_VALUE", false)]
[InlineData(@"directive @dir on
| FIELD_DEFINITION
| ENUM_VALUE", false)]
public void Should_Parse_Directives(string text, bool repeatable)
{
var document = text.Parse();
document.ShouldNotBeNull();
document.Definitions.Count.ShouldBe(1);
document.Definitions[0].ShouldBeAssignableTo<GraphQLDirectiveDefinition>().Repeatable.ShouldBe(repeatable);
}
// http://spec.graphql.org/October2021/#sec--specifiedBy
[Fact]
public void Should_Parse_SpecifiedBy()
{
string text = @"scalar UUID @specifiedBy(url: ""https://tools.ietf.org/html/rfc4122"")";
var document = text.Parse();
document.ShouldNotBeNull();
document.Definitions.Count.ShouldBe(1);
var def = document.Definitions[0].ShouldBeAssignableTo<GraphQLScalarTypeDefinition>();
def.Directives.Count.ShouldBe(1);
def.Directives[0].Name.Value.ShouldBe("specifiedBy");
def.Directives[0].Arguments.Count.ShouldBe(1);
def.Directives[0].Arguments[0].Name.Value.ShouldBe("url");
var value = def.Directives[0].Arguments[0].Value.ShouldBeAssignableTo<GraphQLStringValue>();
value.Value.ShouldBe("https://tools.ietf.org/html/rfc4122");
}
[Theory]
[InlineData(IgnoreOptions.None)]
[InlineData(IgnoreOptions.Comments)]
[InlineData(IgnoreOptions.Locations)]
[InlineData(IgnoreOptions.All)]
public void Should_Parse_Interfaces_Implemented_By_Interface(IgnoreOptions options)
{
string text = "InterfacesOnInterface".ReadGraphQLFile();
var document = text.Parse(new ParserOptions { Ignore = options });
document.Definitions.Count.ShouldBe(4);
var def1 = document.Definitions[0].ShouldBeAssignableTo<GraphQLInterfaceTypeDefinition>();
def1.Name.Value.ShouldBe("Dog");
def1.Interfaces.ShouldBeNull();
var def2 = document.Definitions[1].ShouldBeAssignableTo<GraphQLInterfaceTypeDefinition>();
def2.Name.Value.ShouldBe("Dog");
def2.Interfaces.Count.ShouldBe(1);
def2.Interfaces[0].Name.Value.ShouldBe("Eat");
var def3 = document.Definitions[2].ShouldBeAssignableTo<GraphQLInterfaceTypeDefinition>();
def3.Name.Value.ShouldBe("Dog");
def3.Interfaces.Count.ShouldBe(2);
def3.Interfaces[0].Name.Value.ShouldBe("Eat");
def3.Interfaces[1].Name.Value.ShouldBe("Sleep");
var def4 = document.Definitions[3].ShouldBeAssignableTo<GraphQLInterfaceTypeDefinition>();
def4.Name.Value.ShouldBe("Dog");
def4.Interfaces.Count.ShouldBe(2);
def4.Interfaces[0].Name.Value.ShouldBe("Eat");
def4.Interfaces[1].Name.Value.ShouldBe("Sleep");
def4.Fields.Count.ShouldBe(1);
def4.Fields[0].Name.Value.ShouldBe("name");
}
[Theory]
[InlineData("union Animal = Cat | Dog")]
[InlineData("union Animal = | Cat | Dog")]
[InlineData(@"union Animal =
Cat | Dog")]
[InlineData(@"union Animal =
Cat
| Dog")]
[InlineData(@"union Animal =
| Cat
| Dog")]
[InlineData(@"union Animal =
| Cat
| Dog")]
public void Should_Parse_Unions(string text)
{
var document = text.Parse();
document.ShouldNotBeNull();
}
[Theory]
[InlineData("extend scalar Foo @exportable", ASTNodeKind.ScalarTypeExtension)]
[InlineData("extend type Foo implements Bar @exportable { a: String }", ASTNodeKind.ObjectTypeExtension)]
[InlineData("extend type Foo implements Bar @exportable", ASTNodeKind.ObjectTypeExtension)]
[InlineData("extend type Foo implements Bar { a: String }", ASTNodeKind.ObjectTypeExtension)]
[InlineData("extend type Foo implements Bar", ASTNodeKind.ObjectTypeExtension)]
[InlineData("extend type Foo { a: String }", ASTNodeKind.ObjectTypeExtension)]
[InlineData("extend interface Foo implements Bar @exportable { a: String }", ASTNodeKind.InterfaceTypeExtension)]
[InlineData("extend interface Foo implements Bar @exportable", ASTNodeKind.InterfaceTypeExtension)]
[InlineData("extend interface Foo implements Bar { a: String }", ASTNodeKind.InterfaceTypeExtension)]
[InlineData("extend interface Foo { a: String }", ASTNodeKind.InterfaceTypeExtension)]
[InlineData("extend interface Foo implements Bar", ASTNodeKind.InterfaceTypeExtension)]
[InlineData("extend union Foo @exportable = A | B", ASTNodeKind.UnionTypeExtension)]
[InlineData("extend union Foo = A | B", ASTNodeKind.UnionTypeExtension)]
[InlineData("extend union Foo @exportable", ASTNodeKind.UnionTypeExtension)]
[InlineData("extend enum Foo @exportable { ONE TWO }", ASTNodeKind.EnumTypeExtension)]
[InlineData("extend enum Foo { ONE TWO }", ASTNodeKind.EnumTypeExtension)]
[InlineData("extend enum Foo @exportable", ASTNodeKind.EnumTypeExtension)]
[InlineData("extend input Foo @exportable { a: String }", ASTNodeKind.InputObjectTypeExtension)]
[InlineData("extend input Foo { a: String }", ASTNodeKind.InputObjectTypeExtension)]
[InlineData("extend input Foo @exportable", ASTNodeKind.InputObjectTypeExtension)]
public void Should_Parse_Extensions(string text, ASTNodeKind kind)
{
var document = text.Parse();
document.ShouldNotBeNull();
document.Definitions[0].Kind.ShouldBe(kind);
}
[Theory]
[InlineData("scalar Empty", ASTNodeKind.ScalarTypeDefinition)]
[InlineData("union Empty", ASTNodeKind.UnionTypeDefinition)]
[InlineData("type Empty", ASTNodeKind.ObjectTypeDefinition)]
[InlineData("input Empty", ASTNodeKind.InputObjectTypeDefinition)]
[InlineData("interface Empty", ASTNodeKind.InterfaceTypeDefinition)]
[InlineData("enum Empty", ASTNodeKind.EnumTypeDefinition)]
public void Should_Parse_Empty_Types(string text, ASTNodeKind kind)
{
var document = text.Parse();
document.ShouldNotBeNull();
document.Definitions[0].Kind.ShouldBe(kind);
}
[Theory]
[InlineData(IgnoreOptions.None)]
[InlineData(IgnoreOptions.Comments)]
[InlineData(IgnoreOptions.Locations)]
[InlineData(IgnoreOptions.All)]
public void Descriptions_Should_Read_Correctly(IgnoreOptions options)
{
var document = """"
"Super schema"
schema {
query: String
}
"A JSON scalar"
scalar JSON
"""
Human type
"""