diff --git a/CHANGELOG.md b/CHANGELOG.md index b99e87b..a578397 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # CHANGELOG +## v0.2.12 + +- Fix where the undefined operation type is generated https://github.com/mununki/gqlmerge/pull/47 + ## v0.2.11 - Fixed mis-used rune `[` instead of tokLBracket https://github.com/mununki/gqlmerge/pull/41 diff --git a/command/command.go b/command/command.go index 1714627..a94ac50 100644 --- a/command/command.go +++ b/command/command.go @@ -32,7 +32,7 @@ func (c *Command) Check() error { NotEnoughArgs: "❌ Not enough arguments", OutputFileNeeded: "❌ Output file argument is needed", WrongOption: "❌ Wrong options", - Version: "v0.2.11", + Version: "v0.2.12", } help := flag.Bool("h", false, "show the help") diff --git a/lib/write.go b/lib/write.go index 27c3ab5..8d11ca8 100644 --- a/lib/write.go +++ b/lib/write.go @@ -10,28 +10,25 @@ type MergedSchema struct { } func (ms *MergedSchema) WriteSchema(s *Schema) string { - ms.writeDescriptions(s.SchemaDefinitions[0].Descriptions, 0, true) - ms.buf.WriteString("schema {\n") - ms.addIndent(1) - if s.SchemaDefinitions[0].Query != nil { - ms.buf.WriteString("query: " + *s.SchemaDefinitions[0].Query + "\n") - } else { - ms.buf.WriteString("query: Query\n") - } - ms.addIndent(1) - if s.SchemaDefinitions[0].Mutation != nil { - ms.buf.WriteString("mutation: " + *s.SchemaDefinitions[0].Mutation + "\n") - } else { - ms.buf.WriteString("mutation: Mutation\n") - } - ms.addIndent(1) - if s.SchemaDefinitions[0].Subscription != nil { - ms.buf.WriteString("subscription: " + *s.SchemaDefinitions[0].Subscription + "\n") - } else { - ms.buf.WriteString("subscription: Subscription\n") - } + if (s.SchemaDefinitions[0].Query != nil) || (s.SchemaDefinitions[0].Mutation != nil) || (s.SchemaDefinitions[0].Subscription != nil) { + ms.writeDescriptions(s.SchemaDefinitions[0].Descriptions, 0, true) + ms.buf.WriteString("schema {\n") + ms.addIndent(1) - ms.buf.WriteString("}\n\n") + if s.SchemaDefinitions[0].Query != nil { + ms.buf.WriteString("query: " + *s.SchemaDefinitions[0].Query + "\n") + } + ms.addIndent(1) + if s.SchemaDefinitions[0].Mutation != nil { + ms.buf.WriteString("mutation: " + *s.SchemaDefinitions[0].Mutation + "\n") + } + ms.addIndent(1) + if s.SchemaDefinitions[0].Subscription != nil { + ms.buf.WriteString("subscription: " + *s.SchemaDefinitions[0].Subscription + "\n") + } + + ms.buf.WriteString("}\n\n") + } numOfDirs := len(s.DirectiveDefinitions) if numOfDirs > 0 { diff --git a/test/arg_input/generated.graphql b/test/arg_input/generated.graphql index eb4764c..a768ee2 100644 --- a/test/arg_input/generated.graphql +++ b/test/arg_input/generated.graphql @@ -1,8 +1,6 @@ schema { - query: Query - mutation: Mutation - subscription: Subscription -} + mutation: Mutation + } type Mutation { createLogKo(input: CreateLogInput!): String! diff --git a/test/basic/generated.graphql b/test/basic/generated.graphql index 4681131..c74f761 100644 --- a/test/basic/generated.graphql +++ b/test/basic/generated.graphql @@ -2,8 +2,7 @@ schema { query: Query mutation: Mutation - subscription: Subscription -} + } """ TEST : Directive 1 diff --git a/test/property_type/generated.graphql b/test/property_type/generated.graphql index 4254040..985822a 100644 --- a/test/property_type/generated.graphql +++ b/test/property_type/generated.graphql @@ -1,9 +1,3 @@ -schema { - query: Query - mutation: Mutation - subscription: Subscription -} - type SomePayload { type: String! someKey: String!