diff --git a/lib/graphql.go b/lib/graphql.go index 14b6c22..fbfd473 100644 --- a/lib/graphql.go +++ b/lib/graphql.go @@ -76,16 +76,16 @@ type Arg struct { type Field struct { BaseFileInfo - Name string - Args []*Arg - Type string - Null bool - IsList bool - IsListNull bool - DefaultValue *string - Directives []*Directive - Descriptions *[]string - Comments *[]string + Name string + Args []*Arg + Type string + Null bool + IsList bool + IsListNull bool + DefaultValues *[]string + Directives []*Directive + Descriptions *[]string + Comments *[]string } type Scalar struct { diff --git a/lib/schema.go b/lib/schema.go index bd2e433..3dc4e22 100644 --- a/lib/schema.go +++ b/lib/schema.go @@ -319,6 +319,23 @@ func (s *Schema) Parse(p *Parser) { } else { fd.IsListNull = true } + if p.lex.peek() == '=' { + p.lex.consumeToken(tokEqual) + defaultValues := []string{} + for p.lex.peek() == '[' { + p.lex.consumeIdent(tokLBracket) + for p.lex.peek() != ']' { + tex, _ := p.lex.consumeIdentInclString(tokNumber) + te := tex.String() + defaultValues = append(defaultValues, te) + if p.lex.peek() == ',' { + p.lex.consumeToken(tokComma) + } + } + p.lex.consumeIdent(tokRBracket) + fd.DefaultValues = &defaultValues + } + } } else { fd.IsList = false fd.IsListNull = false @@ -335,7 +352,9 @@ func (s *Schema) Parse(p *Parser) { p.lex.consumeToken(tokEqual) tex, _ := p.lex.consumeIdentInclString(tokNumber) te := tex.String() - fd.DefaultValue = &te + defaultValues := []string{} + defaultValues = append(defaultValues, te) + fd.DefaultValues = &defaultValues } } diff --git a/lib/write.go b/lib/write.go index f56a05d..64008dc 100644 --- a/lib/write.go +++ b/lib/write.go @@ -237,10 +237,17 @@ func (ms *MergedSchema) WriteSchema(s *Schema) string { if p.IsList && !p.IsListNull { ms.buf.WriteString("!") } - if p.DefaultValue != nil { - ms.buf.WriteString(" = " + *p.DefaultValue) + if p.DefaultValues != nil { + if p.IsList { + ms.buf.WriteString(" = ") + ms.buf.WriteString("[") + ms.stitchDefaultValues(p.DefaultValues) + ms.buf.WriteString("]") + } else { + ms.buf.WriteString(" = ") + ms.stitchDefaultValues(p.DefaultValues) + } } - ms.stitchDirectives(p.Directives) ms.buf.WriteString("\n") diff --git a/test/default_value/generated.graphql b/test/default_value/generated.graphql index add7fdd..e947b58 100644 --- a/test/default_value/generated.graphql +++ b/test/default_value/generated.graphql @@ -18,4 +18,5 @@ type Query { input User { name: String! = "woonki" + nicknames: [String!]! = ["mununki", "arnold"] } diff --git a/test/object_extension/generated.graphql b/test/object_extension/generated.graphql index df1238f..5a57a73 100644 --- a/test/object_extension/generated.graphql +++ b/test/object_extension/generated.graphql @@ -1,4 +1,4 @@ -type Person implements Node @talkable @walkable { +type Person implements Node @walkable @talkable { id: ID! createTime: Time! updateTime: Time!