@@ -348,9 +348,10 @@ func parseSchema(s *types.Schema, l *common.Lexer) {
348348 s .Types [input .Name ] = input
349349
350350 case "scalar" :
351+ loc := l .Location ()
351352 name := l .ConsumeIdent ()
352353 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 }
354355
355356 case "directive" :
356357 directive := parseDirectiveDef (l )
@@ -368,7 +369,7 @@ func parseSchema(s *types.Schema, l *common.Lexer) {
368369}
369370
370371func parseObjectDef (l * common.Lexer ) * types.ObjectTypeDefinition {
371- object := & types.ObjectTypeDefinition {Name : l .ConsumeIdent ()}
372+ object := & types.ObjectTypeDefinition {Loc : l . Location (), Name : l .ConsumeIdent ()}
372373
373374 for {
374375 if l .Peek () == '{' {
@@ -403,7 +404,7 @@ func parseObjectDef(l *common.Lexer) *types.ObjectTypeDefinition {
403404}
404405
405406func parseInterfaceDef (l * common.Lexer ) * types.InterfaceTypeDefinition {
406- i := & types.InterfaceTypeDefinition {Name : l .ConsumeIdent ()}
407+ i := & types.InterfaceTypeDefinition {Loc : l . Location (), Name : l .ConsumeIdent ()}
407408
408409 i .Directives = common .ParseDirectives (l )
409410
@@ -415,7 +416,7 @@ func parseInterfaceDef(l *common.Lexer) *types.InterfaceTypeDefinition {
415416}
416417
417418func parseUnionDef (l * common.Lexer ) * types.Union {
418- union := & types.Union {Name : l .ConsumeIdent ()}
419+ union := & types.Union {Loc : l . Location (), Name : l .ConsumeIdent ()}
419420
420421 union .Directives = common .ParseDirectives (l )
421422 l .ConsumeToken ('=' )
@@ -430,6 +431,7 @@ func parseUnionDef(l *common.Lexer) *types.Union {
430431
431432func parseInputDef (l * common.Lexer ) * types.InputObject {
432433 i := & types.InputObject {}
434+ i .Loc = l .Location ()
433435 i .Name = l .ConsumeIdent ()
434436 i .Directives = common .ParseDirectives (l )
435437 l .ConsumeToken ('{' )
@@ -441,13 +443,14 @@ func parseInputDef(l *common.Lexer) *types.InputObject {
441443}
442444
443445func parseEnumDef (l * common.Lexer ) * types.EnumTypeDefinition {
444- enum := & types.EnumTypeDefinition {Name : l .ConsumeIdent ()}
446+ enum := & types.EnumTypeDefinition {Loc : l . Location (), Name : l .ConsumeIdent ()}
445447
446448 enum .Directives = common .ParseDirectives (l )
447449 l .ConsumeToken ('{' )
448450 for l .Peek () != '}' {
449451 v := & types.EnumValueDefinition {
450452 Desc : l .DescComment (),
453+ Loc : l .Location (),
451454 EnumValue : l .ConsumeIdent (),
452455 Directives : common .ParseDirectives (l ),
453456 }
@@ -459,7 +462,8 @@ func parseEnumDef(l *common.Lexer) *types.EnumTypeDefinition {
459462}
460463func parseDirectiveDef (l * common.Lexer ) * types.DirectiveDefinition {
461464 l .ConsumeToken ('@' )
462- d := & types.DirectiveDefinition {Name : l .ConsumeIdent ()}
465+ loc := l .Location ()
466+ d := & types.DirectiveDefinition {Name : l .ConsumeIdent (), Loc : loc }
463467
464468 if l .Peek () == '(' {
465469 l .ConsumeToken ('(' )
@@ -484,6 +488,7 @@ func parseDirectiveDef(l *common.Lexer) *types.DirectiveDefinition {
484488}
485489
486490func parseExtension (s * types.Schema , l * common.Lexer ) {
491+ loc := l .Location ()
487492 switch x := l .ConsumeIdent (); x {
488493 case "schema" :
489494 l .ConsumeToken ('{' )
@@ -497,23 +502,23 @@ func parseExtension(s *types.Schema, l *common.Lexer) {
497502
498503 case "type" :
499504 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 })
501506
502507 case "interface" :
503508 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 })
505510
506511 case "union" :
507512 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 })
509514
510515 case "enum" :
511516 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 })
513518
514519 case "input" :
515520 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 })
517522
518523 default :
519524 // TODO: Add ScalarTypeDefinition when adding directives
@@ -526,6 +531,7 @@ func parseFieldsDef(l *common.Lexer) types.FieldsDefinition {
526531 for l .Peek () != '}' {
527532 f := & types.FieldDefinition {}
528533 f .Desc = l .DescComment ()
534+ f .Loc = l .Location ()
529535 f .Name = l .ConsumeIdent ()
530536 if l .Peek () == '(' {
531537 l .ConsumeToken ('(' )
0 commit comments