@@ -844,6 +844,250 @@ class SchemaParserTests: XCTestCase {
844844 XCTAssert ( result == expected)
845845 }
846846
847+ func testUndefinedType( ) throws {
848+ let source = #"type UndefinedType"#
849+
850+ let expected = Document (
851+ definitions: [
852+ ObjectTypeDefinition ( name: nameNode ( " UndefinedType " ) )
853+ ]
854+ )
855+
856+ let result = try parse ( source: source)
857+ XCTAssert ( result == expected)
858+ }
859+
860+ func testUndefinedInterfaceType( ) throws {
861+ let source = #"interface UndefinedInterface"#
862+
863+ let expected = Document (
864+ definitions: [
865+ InterfaceTypeDefinition (
866+ name: nameNode ( " UndefinedInterface " ) ,
867+ fields: [ ] )
868+ ]
869+ )
870+
871+ let result = try parse ( source: source)
872+ XCTAssert ( result == expected)
873+ }
874+
875+ func testInterfaceExtensionType( ) throws {
876+ let source = #"extend interface Bar @onInterface"#
877+
878+ let expected = Document (
879+ definitions: [
880+ InterfaceExtensionDefinition (
881+ definition: InterfaceTypeDefinition (
882+ name: nameNode ( " Bar " ) ,
883+ directives: [
884+ Directive ( name: nameNode ( " onInterface " ) )
885+ ] ,
886+ fields: [ ] ) )
887+ ]
888+ )
889+
890+ let result = try parse ( source: source)
891+ XCTAssert ( result == expected)
892+ }
893+
894+ func testUnionPipe( ) throws {
895+ let source = #"union AnnotatedUnionTwo @onUnion = | A | B"#
896+
897+ let expected = Document (
898+ definitions: [
899+ UnionTypeDefinition (
900+ name: nameNode ( " AnnotatedUnionTwo " ) ,
901+ directives: [
902+ Directive ( name: nameNode ( " onUnion " ) )
903+ ] ,
904+ types: [
905+ NamedType ( name: nameNode ( " A " ) ) ,
906+ NamedType ( name: nameNode ( " B " ) ) ,
907+ ] )
908+ ]
909+ )
910+
911+ let result = try parse ( source: source)
912+ XCTAssert ( result == expected)
913+ }
914+
915+ func testExtendScalar( ) throws {
916+ let source = #"extend scalar CustomScalar @onScalar"#
917+
918+ let expected = Document (
919+ definitions: [
920+ ScalarExtensionDefinition (
921+ definition: ScalarTypeDefinition (
922+ name: nameNode ( " CustomScalar " ) ,
923+ directives: [
924+ Directive ( name: nameNode ( " onScalar " ) )
925+ ]
926+ )
927+ )
928+ ]
929+ )
930+
931+ let result = try parse ( source: source)
932+ XCTAssert ( result == expected)
933+ }
934+
935+ func testUndefinedUnion( ) throws {
936+ let source = #"union UndefinedUnion"#
937+
938+ let expected = Document (
939+ definitions: [
940+ UnionTypeDefinition (
941+ name: nameNode ( " UndefinedUnion " ) ,
942+ types: [ ]
943+ )
944+ ]
945+ )
946+
947+ let result = try parse ( source: source)
948+ XCTAssert ( result == expected)
949+ }
950+
951+ func testExtendUnion( ) throws {
952+ let source = #"extend union Feed = Photo | Video"#
953+
954+ let expected = Document (
955+ definitions: [
956+ UnionExtensionDefinition (
957+ definition: UnionTypeDefinition (
958+ name: nameNode ( " Feed " ) ,
959+ types: [
960+ namedTypeNode ( " Photo " ) ,
961+ namedTypeNode ( " Video " ) ,
962+ ]
963+ )
964+ )
965+ ]
966+ )
967+
968+ let result = try parse ( source: source)
969+ XCTAssert ( result == expected)
970+ }
971+
972+ func testUndefinedEnum( ) throws {
973+ let source = #"enum UndefinedEnum"#
974+
975+ let expected = Document (
976+ definitions: [
977+ EnumTypeDefinition (
978+ name: nameNode ( " UndefinedEnum " ) ,
979+ values: [ ]
980+ )
981+ ]
982+ )
983+
984+ let result = try parse ( source: source)
985+ XCTAssert ( result == expected)
986+ }
987+
988+ func testEnumExtension( ) throws {
989+ let source = #"extend enum Site @onEnum"#
990+
991+ let expected = Document (
992+ definitions: [
993+ EnumExtensionDefinition (
994+ definition: EnumTypeDefinition (
995+ name: nameNode ( " Site " ) ,
996+ directives: [
997+ Directive ( name: nameNode ( " onEnum " ) )
998+ ] ,
999+ values: [ ]
1000+ )
1001+ )
1002+ ]
1003+ )
1004+
1005+ let result = try parse ( source: source)
1006+ XCTAssert ( result == expected)
1007+ }
1008+
1009+ func testUndefinedInput( ) throws {
1010+ let source = #"input UndefinedInput"#
1011+
1012+ let expected = Document (
1013+ definitions: [
1014+ InputObjectTypeDefinition (
1015+ name: nameNode ( " UndefinedInput " ) ,
1016+ fields: [ ]
1017+ )
1018+ ]
1019+ )
1020+
1021+ let result = try parse ( source: source)
1022+ XCTAssert ( result == expected)
1023+ }
1024+
1025+ func testInputExtension( ) throws {
1026+ let source = #"extend input InputType"#
1027+
1028+ let expected = Document (
1029+ definitions: [
1030+ InputObjectExtensionDefinition (
1031+ definition: InputObjectTypeDefinition (
1032+ name: nameNode ( " InputType " ) ,
1033+ fields: [ ]
1034+ )
1035+ )
1036+ ]
1037+ )
1038+
1039+ let result = try parse ( source: source)
1040+ XCTAssert ( result == expected)
1041+ }
1042+
1043+ func testDirectivePipe( ) throws {
1044+ let source = """
1045+ directive @include2 on
1046+ | FIELD
1047+ | FRAGMENT_SPREAD
1048+ | INLINE_FRAGMENT
1049+ """
1050+
1051+ let expected = Document (
1052+ definitions: [
1053+ DirectiveDefinition (
1054+ name: nameNode ( " include2 " ) ,
1055+ locations: [
1056+ nameNode ( " FIELD " ) ,
1057+ nameNode ( " FRAGMENT_SPREAD " ) ,
1058+ nameNode ( " INLINE_FRAGMENT " )
1059+ ] )
1060+ ]
1061+ )
1062+
1063+ let result = try parse ( source: source)
1064+ XCTAssert ( result == expected)
1065+ }
1066+
1067+ func testDirectiveRepeatable( ) throws {
1068+ let source = """
1069+ directive @myRepeatableDir repeatable on
1070+ | OBJECT
1071+ | INTERFACE
1072+ """
1073+
1074+ let expected = Document (
1075+ definitions: [
1076+ DirectiveDefinition (
1077+ name: nameNode ( " myRepeatableDir " ) ,
1078+ locations: [
1079+ nameNode ( " OBJECT " ) ,
1080+ nameNode ( " INTERFACE " ) ,
1081+ ] ,
1082+ repeatable: true
1083+ )
1084+ ]
1085+ )
1086+
1087+ let result = try parse ( source: source)
1088+ XCTAssert ( result == expected)
1089+ }
1090+
8471091 func testKitchenSink( ) throws {
8481092 guard
8491093 let url = Bundle . module. url (
0 commit comments