@@ -348,9 +348,10 @@ func parseSchema(s *types.Schema, l *common.Lexer) {
348
348
s .Types [input .Name ] = input
349
349
350
350
case "scalar" :
351
+ loc := l .Location ()
351
352
name := l .ConsumeIdent ()
352
353
directives := common .ParseDirectives (l )
353
- s .Types [name ] = & types.ScalarTypeDefinition {Name : name , Desc : desc , Directives : directives }
354
+ s .Types [name ] = & types.ScalarTypeDefinition {Name : name , Desc : desc , Directives : directives , Loc : loc }
354
355
355
356
case "directive" :
356
357
directive := parseDirectiveDef (l )
@@ -368,7 +369,7 @@ func parseSchema(s *types.Schema, l *common.Lexer) {
368
369
}
369
370
370
371
func parseObjectDef (l * common.Lexer ) * types.ObjectTypeDefinition {
371
- object := & types.ObjectTypeDefinition {Name : l .ConsumeIdent ()}
372
+ object := & types.ObjectTypeDefinition {Loc : l . Location (), Name : l .ConsumeIdent ()}
372
373
373
374
for {
374
375
if l .Peek () == '{' {
@@ -403,7 +404,7 @@ func parseObjectDef(l *common.Lexer) *types.ObjectTypeDefinition {
403
404
}
404
405
405
406
func parseInterfaceDef (l * common.Lexer ) * types.InterfaceTypeDefinition {
406
- i := & types.InterfaceTypeDefinition {Name : l .ConsumeIdent ()}
407
+ i := & types.InterfaceTypeDefinition {Loc : l . Location (), Name : l .ConsumeIdent ()}
407
408
408
409
i .Directives = common .ParseDirectives (l )
409
410
@@ -415,7 +416,7 @@ func parseInterfaceDef(l *common.Lexer) *types.InterfaceTypeDefinition {
415
416
}
416
417
417
418
func parseUnionDef (l * common.Lexer ) * types.Union {
418
- union := & types.Union {Name : l .ConsumeIdent ()}
419
+ union := & types.Union {Loc : l . Location (), Name : l .ConsumeIdent ()}
419
420
420
421
union .Directives = common .ParseDirectives (l )
421
422
l .ConsumeToken ('=' )
@@ -430,6 +431,7 @@ func parseUnionDef(l *common.Lexer) *types.Union {
430
431
431
432
func parseInputDef (l * common.Lexer ) * types.InputObject {
432
433
i := & types.InputObject {}
434
+ i .Loc = l .Location ()
433
435
i .Name = l .ConsumeIdent ()
434
436
i .Directives = common .ParseDirectives (l )
435
437
l .ConsumeToken ('{' )
@@ -441,13 +443,14 @@ func parseInputDef(l *common.Lexer) *types.InputObject {
441
443
}
442
444
443
445
func parseEnumDef (l * common.Lexer ) * types.EnumTypeDefinition {
444
- enum := & types.EnumTypeDefinition {Name : l .ConsumeIdent ()}
446
+ enum := & types.EnumTypeDefinition {Loc : l . Location (), Name : l .ConsumeIdent ()}
445
447
446
448
enum .Directives = common .ParseDirectives (l )
447
449
l .ConsumeToken ('{' )
448
450
for l .Peek () != '}' {
449
451
v := & types.EnumValueDefinition {
450
452
Desc : l .DescComment (),
453
+ Loc : l .Location (),
451
454
EnumValue : l .ConsumeIdent (),
452
455
Directives : common .ParseDirectives (l ),
453
456
}
@@ -459,7 +462,8 @@ func parseEnumDef(l *common.Lexer) *types.EnumTypeDefinition {
459
462
}
460
463
func parseDirectiveDef (l * common.Lexer ) * types.DirectiveDefinition {
461
464
l .ConsumeToken ('@' )
462
- d := & types.DirectiveDefinition {Name : l .ConsumeIdent ()}
465
+ loc := l .Location ()
466
+ d := & types.DirectiveDefinition {Name : l .ConsumeIdent (), Loc : loc }
463
467
464
468
if l .Peek () == '(' {
465
469
l .ConsumeToken ('(' )
@@ -484,6 +488,7 @@ func parseDirectiveDef(l *common.Lexer) *types.DirectiveDefinition {
484
488
}
485
489
486
490
func parseExtension (s * types.Schema , l * common.Lexer ) {
491
+ loc := l .Location ()
487
492
switch x := l .ConsumeIdent (); x {
488
493
case "schema" :
489
494
l .ConsumeToken ('{' )
@@ -497,23 +502,23 @@ func parseExtension(s *types.Schema, l *common.Lexer) {
497
502
498
503
case "type" :
499
504
obj := parseObjectDef (l )
500
- s .Extensions = append (s .Extensions , & types.Extension {Type : obj })
505
+ s .Extensions = append (s .Extensions , & types.Extension {Type : obj , Loc : loc })
501
506
502
507
case "interface" :
503
508
iface := parseInterfaceDef (l )
504
- s .Extensions = append (s .Extensions , & types.Extension {Type : iface })
509
+ s .Extensions = append (s .Extensions , & types.Extension {Type : iface , Loc : loc })
505
510
506
511
case "union" :
507
512
union := parseUnionDef (l )
508
- s .Extensions = append (s .Extensions , & types.Extension {Type : union })
513
+ s .Extensions = append (s .Extensions , & types.Extension {Type : union , Loc : loc })
509
514
510
515
case "enum" :
511
516
enum := parseEnumDef (l )
512
- s .Extensions = append (s .Extensions , & types.Extension {Type : enum })
517
+ s .Extensions = append (s .Extensions , & types.Extension {Type : enum , Loc : loc })
513
518
514
519
case "input" :
515
520
input := parseInputDef (l )
516
- s .Extensions = append (s .Extensions , & types.Extension {Type : input })
521
+ s .Extensions = append (s .Extensions , & types.Extension {Type : input , Loc : loc })
517
522
518
523
default :
519
524
// TODO: Add ScalarTypeDefinition when adding directives
@@ -526,6 +531,7 @@ func parseFieldsDef(l *common.Lexer) types.FieldsDefinition {
526
531
for l .Peek () != '}' {
527
532
f := & types.FieldDefinition {}
528
533
f .Desc = l .DescComment ()
534
+ f .Loc = l .Location ()
529
535
f .Name = l .ConsumeIdent ()
530
536
if l .Peek () == '(' {
531
537
l .ConsumeToken ('(' )
0 commit comments