From 09d6d8b20f26dcee2f3349438b800cb1253aee6a Mon Sep 17 00:00:00 2001 From: mununki Date: Thu, 14 Dec 2023 19:59:12 +0900 Subject: [PATCH 1/2] not write the undefined operation types --- lib/write.go | 39 +++++++++++++--------------- test/arg_input/generated.graphql | 6 ++--- test/basic/generated.graphql | 3 +-- test/property_type/generated.graphql | 6 ----- 4 files changed, 21 insertions(+), 33 deletions(-) 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! From b8ecfc4a976a585c0943fc53a6a528464af75d01 Mon Sep 17 00:00:00 2001 From: mununki Date: Thu, 14 Dec 2023 20:02:25 +0900 Subject: [PATCH 2/2] set version 0.2.12 --- CHANGELOG.md | 4 ++++ command/command.go | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) 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")