Skip to content

Commit

Permalink
Merge pull request #47 from mununki/fix-unused-operation-def
Browse files Browse the repository at this point in the history
Not writing the undefined operation types
  • Loading branch information
mununki authored Dec 14, 2023
2 parents 2015ef4 + b8ecfc4 commit b52b375
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 34 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion command/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
39 changes: 18 additions & 21 deletions lib/write.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
6 changes: 2 additions & 4 deletions test/arg_input/generated.graphql
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
schema {
query: Query
mutation: Mutation
subscription: Subscription
}
mutation: Mutation
}

type Mutation {
createLogKo(input: CreateLogInput!): String!
Expand Down
3 changes: 1 addition & 2 deletions test/basic/generated.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@
schema {
query: Query
mutation: Mutation
subscription: Subscription
}
}

"""
TEST : Directive 1
Expand Down
6 changes: 0 additions & 6 deletions test/property_type/generated.graphql
Original file line number Diff line number Diff line change
@@ -1,9 +1,3 @@
schema {
query: Query
mutation: Mutation
subscription: Subscription
}

type SomePayload {
type: String!
someKey: String!
Expand Down

0 comments on commit b52b375

Please sign in to comment.