@@ -311,67 +311,59 @@ class SchemaParserTests: XCTestCase {
311311 )
312312 }
313313
314- func testSchemeExtension( ) throws {
315- // Based on Apollo Federation example schema: https://github.com/apollographql/apollo-federation-subgraph-compatibility/blob/main/COMPATIBILITY.md#products-schema-to-be-implemented-by-library-maintainers
316- let source =
317- """
318- extend schema
319- @link(
320- url: " https://specs.apollo.dev/federation/v2.0 " ,
321- import: [
322- " @extends " ,
323- " @external " ,
324- " @key " ,
325- " @inaccessible " ,
326- " @override " ,
327- " @provides " ,
328- " @requires " ,
329- " @shareable " ,
330- " @tag "
314+ func testSchemaExtension( ) throws {
315+ XCTAssertEqual (
316+ try parse ( source: """
317+ extend schema {
318+ mutation: Mutation
319+ }
320+ """ ) ,
321+ Document (
322+ definitions: [
323+ SchemaExtensionDefinition (
324+ definition: SchemaDefinition (
325+ directives: [ ] ,
326+ operationTypes: [
327+ OperationTypeDefinition (
328+ operation: . mutation,
329+ type: . init( name: . init( value: " Mutation " ) )
330+ ) ,
331+ ]
332+ )
333+ ) ,
331334 ]
332- )
333- """
335+ )
336+ )
337+ }
334338
335- let expected = Document (
336- definitions: [
337- SchemaExtensionDefinition (
338- definition: SchemaDefinition (
339- directives: [
340- Directive (
341- name: nameNode ( " link " ) ,
342- arguments: [
343- Argument (
344- name: nameNode ( " url " ) ,
345- value: StringValue (
346- value: " https://specs.apollo.dev/federation/v2.0 " ,
347- block: false
348- )
349- ) ,
350- Argument (
351- name: nameNode ( " import " ) ,
352- value: ListValue ( values: [
353- StringValue ( value: " @extends " , block: false ) ,
354- StringValue ( value: " @external " , block: false ) ,
355- StringValue ( value: " @key " , block: false ) ,
356- StringValue ( value: " @inaccessible " , block: false ) ,
357- StringValue ( value: " @override " , block: false ) ,
358- StringValue ( value: " @provides " , block: false ) ,
359- StringValue ( value: " @requires " , block: false ) ,
360- StringValue ( value: " @shareable " , block: false ) ,
361- StringValue ( value: " @tag " , block: false ) ,
362- ] )
363- ) ,
364- ]
365- ) ,
366- ] ,
367- operationTypes: [ ]
368- )
369- ) ,
370- ]
339+ func testSchemaExtensionWithOnlyDirectives( ) throws {
340+ XCTAssertEqual (
341+ try parse ( source: " extend schema @directive " ) ,
342+ Document (
343+ definitions: [
344+ SchemaExtensionDefinition (
345+ definition: SchemaDefinition (
346+ directives: [
347+ Directive ( name: . init( value: " directive " ) ) ,
348+ ] ,
349+ operationTypes: [ ]
350+ )
351+ ) ,
352+ ]
353+ )
371354 )
355+ }
372356
373- let result = try parse ( source: source)
374- XCTAssert ( result == expected)
357+ func testSchemaExtensionWithoutAnythingThrows( ) throws {
358+ XCTAssertThrowsError (
359+ try parse ( source: " extend schema " )
360+ )
361+ }
362+
363+ func testSchemaExtensionWithInvalidOperationTypeThrows( ) throws {
364+ XCTAssertThrowsError (
365+ try parse ( source: " extend schema { unknown: SomeType } " )
366+ )
375367 }
376368
377369 func testSimpleNonNullType( ) throws {
@@ -397,6 +389,26 @@ class SchemaParserTests: XCTestCase {
397389 XCTAssert ( result == expected)
398390 }
399391
392+ func testSimpleInterfaceInheritingInterface( ) throws {
393+ XCTAssertEqual (
394+ try parse ( source: " interface Hello implements World { field: String } " ) ,
395+ Document (
396+ definitions: [
397+ InterfaceTypeDefinition (
398+ name: nameNode ( " Hello " ) ,
399+ interfaces: [ typeNode ( " World " ) ] ,
400+ fields: [
401+ FieldDefinition (
402+ name: . init( value: " field " ) ,
403+ type: NamedType ( name: . init( value: " String " ) )
404+ ) ,
405+ ]
406+ ) ,
407+ ]
408+ )
409+ )
410+ }
411+
400412 func testSimpleTypeInheritingInterface( ) throws {
401413 let source = " type Hello implements World { } "
402414
@@ -432,6 +444,71 @@ class SchemaParserTests: XCTestCase {
432444 XCTAssert ( result == expected)
433445 }
434446
447+ func testSimpleInterfaceInheritingMultipleInterfaces( ) throws {
448+ XCTAssertEqual (
449+ try parse ( source: " interface Hello implements Wo & rld { field: String } " ) ,
450+ Document (
451+ definitions: [
452+ InterfaceTypeDefinition (
453+ name: nameNode ( " Hello " ) ,
454+ interfaces: [
455+ typeNode ( " Wo " ) ,
456+ typeNode ( " rld " ) ,
457+ ] ,
458+ fields: [
459+ FieldDefinition (
460+ name: . init( value: " field " ) ,
461+ type: NamedType ( name: . init( value: " String " ) )
462+ ) ,
463+ ]
464+ ) ,
465+ ]
466+ )
467+ )
468+ }
469+
470+ func testSimpleTypeInheritingMultipleInterfacesWithLeadingAmbersand( ) throws {
471+ let source = " type Hello implements & Wo & rld { } "
472+
473+ let expected = Document (
474+ definitions: [
475+ ObjectTypeDefinition (
476+ name: nameNode ( " Hello " ) ,
477+ interfaces: [
478+ typeNode ( " Wo " ) ,
479+ typeNode ( " rld " ) ,
480+ ]
481+ ) ,
482+ ]
483+ )
484+
485+ let result = try parse ( source: source)
486+ XCTAssert ( result == expected)
487+ }
488+
489+ func testSimpleInterfaceInheritingMultipleInterfacesWithLeadingAmbersand( ) throws {
490+ XCTAssertEqual (
491+ try parse ( source: " interface Hello implements & Wo & rld { field: String } " ) ,
492+ Document (
493+ definitions: [
494+ InterfaceTypeDefinition (
495+ name: nameNode ( " Hello " ) ,
496+ interfaces: [
497+ typeNode ( " Wo " ) ,
498+ typeNode ( " rld " ) ,
499+ ] ,
500+ fields: [
501+ FieldDefinition (
502+ name: . init( value: " field " ) ,
503+ type: NamedType ( name: . init( value: " String " ) )
504+ ) ,
505+ ]
506+ ) ,
507+ ]
508+ )
509+ )
510+ }
511+
435512 func testSingleValueEnum( ) throws {
436513 let source = " enum Hello { WORLD } "
437514
@@ -1310,4 +1387,67 @@ class SchemaParserTests: XCTestCase {
13101387
13111388 _ = try parse ( source: kitchenSink)
13121389 }
1390+
1391+ func testSchemeExtension( ) throws {
1392+ // Based on Apollo Federation example schema: https://github.com/apollographql/apollo-federation-subgraph-compatibility/blob/main/COMPATIBILITY.md#products-schema-to-be-implemented-by-library-maintainers
1393+ let source =
1394+ """
1395+ extend schema
1396+ @link(
1397+ url: " https://specs.apollo.dev/federation/v2.0 " ,
1398+ import: [
1399+ " @extends " ,
1400+ " @external " ,
1401+ " @key " ,
1402+ " @inaccessible " ,
1403+ " @override " ,
1404+ " @provides " ,
1405+ " @requires " ,
1406+ " @shareable " ,
1407+ " @tag "
1408+ ]
1409+ )
1410+ """
1411+
1412+ let expected = Document (
1413+ definitions: [
1414+ SchemaExtensionDefinition (
1415+ definition: SchemaDefinition (
1416+ directives: [
1417+ Directive (
1418+ name: nameNode ( " link " ) ,
1419+ arguments: [
1420+ Argument (
1421+ name: nameNode ( " url " ) ,
1422+ value: StringValue (
1423+ value: " https://specs.apollo.dev/federation/v2.0 " ,
1424+ block: false
1425+ )
1426+ ) ,
1427+ Argument (
1428+ name: nameNode ( " import " ) ,
1429+ value: ListValue ( values: [
1430+ StringValue ( value: " @extends " , block: false ) ,
1431+ StringValue ( value: " @external " , block: false ) ,
1432+ StringValue ( value: " @key " , block: false ) ,
1433+ StringValue ( value: " @inaccessible " , block: false ) ,
1434+ StringValue ( value: " @override " , block: false ) ,
1435+ StringValue ( value: " @provides " , block: false ) ,
1436+ StringValue ( value: " @requires " , block: false ) ,
1437+ StringValue ( value: " @shareable " , block: false ) ,
1438+ StringValue ( value: " @tag " , block: false ) ,
1439+ ] )
1440+ ) ,
1441+ ]
1442+ ) ,
1443+ ] ,
1444+ operationTypes: [ ]
1445+ )
1446+ ) ,
1447+ ]
1448+ )
1449+
1450+ let result = try parse ( source: source)
1451+ XCTAssert ( result == expected)
1452+ }
13131453}
0 commit comments