Skip to content

Commit

Permalink
Fixing enum value definitions
Browse files Browse the repository at this point in the history
  • Loading branch information
pkedy committed Nov 7, 2021
1 parent 5b0d96e commit b062dc3
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
6 changes: 5 additions & 1 deletion ast/definitions.go
Original file line number Diff line number Diff line change
Expand Up @@ -271,14 +271,18 @@ type EnumValueDefinition struct {
BaseNode
Name *Name `json:"name"`
Description *StringValue `json:"description,omitempty"` // Optional
Index *IntValue `json:"index"`
Display *StringValue `json:"display,omitempty"` // Optional
AnnotatedNode
}

func NewEnumValueDefinition(loc *Location, name *Name, description *StringValue, annotations []*Annotation) *EnumValueDefinition {
func NewEnumValueDefinition(loc *Location, name *Name, description *StringValue, index *IntValue, display *StringValue, annotations []*Annotation) *EnumValueDefinition {
return &EnumValueDefinition{
BaseNode: BaseNode{kinds.EnumValueDefinition, loc},
Name: name,
Description: description,
Index: index,
Display: display,
AnnotatedNode: AnnotatedNode{annotations},
}
}
Expand Down
20 changes: 20 additions & 0 deletions parser/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -1178,14 +1178,34 @@ func parseEnumValueDefinition(parser *Parser) (interface{}, error) {
if err != nil {
return nil, err
}
_, err = expect(parser, lexer.TokenKind[lexer.EQUALS])
if err != nil {
return nil, err
}
token, err := expect(parser, lexer.TokenKind[lexer.INT])
if err != nil {
return nil, err
}
indexValue, err := strconv.Atoi(token.Value)
index := ast.NewIntValue(loc(parser, token.Start), indexValue)
annotations, err := parseAnnotations(parser)
if err != nil {
return nil, err
}
var display *ast.StringValue
if _, ok, err := optionalKeyWord(parser, "as"); err != nil {
return nil, err
} else if ok {
if display, err = parseStringLiteral(parser); err != nil {
return nil, err
}
}
return ast.NewEnumValueDefinition(
loc(parser, start),
name,
description,
index,
display,
annotations,
), nil
}
Expand Down

0 comments on commit b062dc3

Please sign in to comment.