Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add NullValue to allow sending null in a value literal #460

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions language/ast/values.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ var _ Value = (*BooleanValue)(nil)
var _ Value = (*EnumValue)(nil)
var _ Value = (*ListValue)(nil)
var _ Value = (*ObjectValue)(nil)
var _ Value = (*NullValue)(nil)

// Variable implements Node, Value
type Variable struct {
Expand Down Expand Up @@ -300,3 +301,31 @@ func (f *ObjectField) GetLoc() *Location {
func (f *ObjectField) GetValue() interface{} {
return f.Value
}

// NullField implements Node, Value
type NullValue struct {
Kind string
Loc *Location
}

func NewNullValue(v *NullValue) *NullValue {
if v == nil {
v = &NullValue{}
}
return &NullValue{
Kind: kinds.NullValue,
Loc: v.Loc,
}
}

func (v *NullValue) GetKind() string {
return v.Kind
}

func (v *NullValue) GetLoc() *Location {
return v.Loc
}

func (v *NullValue) GetValue() interface{} {
return nil
}
1 change: 1 addition & 0 deletions language/kinds/kinds.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ const (
ListValue = "ListValue"
ObjectValue = "ObjectValue"
ObjectField = "ObjectField"
NullValue = "NullValue"

// Directives
Directive = "Directive"
Expand Down
14 changes: 10 additions & 4 deletions language/parser/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -610,15 +610,21 @@ func parseValueLiteral(parser *Parser, isConst bool) (ast.Value, error) {
Value: value,
Loc: loc(parser, token.Start),
}), nil
} else if token.Value != "null" {
} else if token.Value == "null" {
if err := advance(parser); err != nil {
return nil, err
}
return ast.NewEnumValue(&ast.EnumValue{
Value: token.Value,
Loc: loc(parser, token.Start),
return ast.NewNullValue(&ast.NullValue{
Loc: loc(parser, token.Start),
}), nil
}
if err := advance(parser); err != nil {
return nil, err
}
return ast.NewEnumValue(&ast.EnumValue{
Value: token.Value,
Loc: loc(parser, token.Start),
}), nil
case lexer.DOLLAR:
if !isConst {
return parseVariable(parser)
Expand Down