@@ -9,7 +9,7 @@ import { inspect } from '../../jsutils/inspect';
9
9
import { Kind } from '../kinds' ;
10
10
import { Source } from '../source' ;
11
11
import { TokenKind } from '../tokenKind' ;
12
- import { parse , parseValue , parseType } from '../parser' ;
12
+ import { parse , parseValue , parseType , parseSchemaCoordinate } from '../parser' ;
13
13
14
14
import { toJSONDeep } from './toJSONDeep' ;
15
15
@@ -531,4 +531,129 @@ describe('Parser', () => {
531
531
} ) ;
532
532
} ) ;
533
533
} ) ;
534
+
535
+ describe ( 'parseSchemaCoordinate' , ( ) => {
536
+ it ( 'parses Name' , ( ) => {
537
+ const result = parseSchemaCoordinate ( 'MyType' ) ;
538
+ expect ( toJSONDeep ( result ) ) . to . deep . equal ( {
539
+ kind : Kind . SCHEMA_COORDINATE ,
540
+ loc : { start : 0 , end : 6 } ,
541
+ isDirective : false ,
542
+ name : {
543
+ kind : Kind . NAME ,
544
+ loc : { start : 0 , end : 6 } ,
545
+ value : 'MyType' ,
546
+ } ,
547
+ fieldName : undefined ,
548
+ argumentName : undefined ,
549
+ } ) ;
550
+ } ) ;
551
+
552
+ it ( 'parses Name . Name' , ( ) => {
553
+ const result = parseSchemaCoordinate ( 'MyType.field' ) ;
554
+ expect ( toJSONDeep ( result ) ) . to . deep . equal ( {
555
+ kind : Kind . SCHEMA_COORDINATE ,
556
+ loc : { start : 0 , end : 12 } ,
557
+ isDirective : false ,
558
+ name : {
559
+ kind : Kind . NAME ,
560
+ loc : { start : 0 , end : 6 } ,
561
+ value : 'MyType' ,
562
+ } ,
563
+ fieldName : {
564
+ kind : Kind . NAME ,
565
+ loc : { start : 7 , end : 12 } ,
566
+ value : 'field' ,
567
+ } ,
568
+ argumentName : undefined ,
569
+ } ) ;
570
+ } ) ;
571
+
572
+ it ( 'rejects Name . Name . Name' , ( ) => {
573
+ expect ( ( ) => parseSchemaCoordinate ( 'MyType.field.deep' ) )
574
+ . to . throw ( )
575
+ . to . deep . equal ( {
576
+ message : 'Syntax Error: Expected <EOF>, found ".".' ,
577
+ locations : [ { line : 1 , column : 13 } ] ,
578
+ } ) ;
579
+ } ) ;
580
+
581
+ it ( 'parses Name . Name ( Name : )' , ( ) => {
582
+ const result = parseSchemaCoordinate ( 'MyType.field(arg:)' ) ;
583
+ expect ( toJSONDeep ( result ) ) . to . deep . equal ( {
584
+ kind : Kind . SCHEMA_COORDINATE ,
585
+ loc : { start : 0 , end : 18 } ,
586
+ isDirective : false ,
587
+ name : {
588
+ kind : Kind . NAME ,
589
+ loc : { start : 0 , end : 6 } ,
590
+ value : 'MyType' ,
591
+ } ,
592
+ fieldName : {
593
+ kind : Kind . NAME ,
594
+ loc : { start : 7 , end : 12 } ,
595
+ value : 'field' ,
596
+ } ,
597
+ argumentName : {
598
+ kind : Kind . NAME ,
599
+ loc : { start : 13 , end : 16 } ,
600
+ value : 'arg' ,
601
+ } ,
602
+ } ) ;
603
+ } ) ;
604
+
605
+ it ( 'rejects Name . Name ( Name : Name )' , ( ) => {
606
+ expect ( ( ) => parseSchemaCoordinate ( 'MyType.field(arg: value)' ) )
607
+ . to . throw ( )
608
+ . to . deep . equal ( {
609
+ message : 'Syntax Error: Expected ")", found Name "value".' ,
610
+ locations : [ { line : 1 , column : 19 } ] ,
611
+ } ) ;
612
+ } ) ;
613
+
614
+ it ( 'parses @ Name' , ( ) => {
615
+ const result = parseSchemaCoordinate ( '@myDirective' ) ;
616
+ expect ( toJSONDeep ( result ) ) . to . deep . equal ( {
617
+ kind : Kind . SCHEMA_COORDINATE ,
618
+ loc : { start : 0 , end : 12 } ,
619
+ isDirective : true ,
620
+ name : {
621
+ kind : Kind . NAME ,
622
+ loc : { start : 1 , end : 12 } ,
623
+ value : 'myDirective' ,
624
+ } ,
625
+ fieldName : undefined ,
626
+ argumentName : undefined ,
627
+ } ) ;
628
+ } ) ;
629
+
630
+ it ( 'parses @ Name ( Name : )' , ( ) => {
631
+ const result = parseSchemaCoordinate ( '@myDirective(arg:)' ) ;
632
+ expect ( toJSONDeep ( result ) ) . to . deep . equal ( {
633
+ kind : Kind . SCHEMA_COORDINATE ,
634
+ loc : { start : 0 , end : 18 } ,
635
+ isDirective : true ,
636
+ name : {
637
+ kind : Kind . NAME ,
638
+ loc : { start : 1 , end : 12 } ,
639
+ value : 'myDirective' ,
640
+ } ,
641
+ fieldName : undefined ,
642
+ argumentName : {
643
+ kind : Kind . NAME ,
644
+ loc : { start : 13 , end : 16 } ,
645
+ value : 'arg' ,
646
+ } ,
647
+ } ) ;
648
+ } ) ;
649
+
650
+ it ( 'rejects @ Name . Name' , ( ) => {
651
+ expect ( ( ) => parseSchemaCoordinate ( '@myDirective.field' ) )
652
+ . to . throw ( )
653
+ . to . deep . equal ( {
654
+ message : 'Syntax Error: Expected <EOF>, found ".".' ,
655
+ locations : [ { line : 1 , column : 13 } ] ,
656
+ } ) ;
657
+ } ) ;
658
+ } ) ;
534
659
} ) ;
0 commit comments