Skip to content

Commit

Permalink
fix handling default value in input object
Browse files Browse the repository at this point in the history
  • Loading branch information
mununki committed Apr 2, 2024
1 parent 5f17c77 commit 1aeac27
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 0 deletions.
1 change: 1 addition & 0 deletions lib/graphql.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ type Field struct {
Null bool
IsList bool
IsListNull bool
DefaultValue *string
Directives []*Directive
Descriptions *[]string
Comments *[]string
Expand Down
7 changes: 7 additions & 0 deletions lib/schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,13 @@ func (s *Schema) Parse(p *Parser) {
} else {
fd.Null = true
}

if p.lex.peek() == '=' {
p.lex.consumeToken(tokEqual)
tex, _ := p.lex.consumeIdentInclString(tokNumber)
te := tex.String()
fd.DefaultValue = &te
}
}

fd.Directives = p.parseDirectives()
Expand Down
3 changes: 3 additions & 0 deletions lib/write.go
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,9 @@ func (ms *MergedSchema) WriteSchema(s *Schema) string {
if p.IsList && !p.IsListNull {
ms.buf.WriteString("!")
}
if p.DefaultValue != nil {
ms.buf.WriteString(" = " + *p.DefaultValue)
}

ms.stitchDirectives(p.Directives)

Expand Down
3 changes: 3 additions & 0 deletions test/default_value/generated.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,6 @@ type Query {



input User {
name: String! = "woonki"
}

0 comments on commit 1aeac27

Please sign in to comment.