Skip to content

Commit

Permalink
Fix infinity loop
Browse files Browse the repository at this point in the history
skip already exist type
  • Loading branch information
Yamashou committed Dec 2, 2024
1 parent 5c166c5 commit fd37f93
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 6 deletions.
2 changes: 1 addition & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"github.com/urfave/cli/v2"
)

const version = "0.27.1"
const version = "0.27.2"

var versionCmd = &cli.Command{
Name: "version",
Expand Down
25 changes: 20 additions & 5 deletions querydocument/query_document.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,13 +91,28 @@ func CollectTypesFromQueryDocuments(schema *ast.Schema, queryDocuments []*ast.Qu

// collectInputObjectFields recursively collects types from input object fields
func collectInputObjectFields(def *ast.Definition, schema *ast.Schema, usedTypes map[string]bool) {
// Skip if type has already been processed
if _, ok := usedTypes[def.Name]; ok {
return
}
usedTypes[def.Name] = true

for _, field := range def.Fields {
typeName := field.Type.Name()
usedTypes[typeName] = true
// Get the actual type name
typeName := field.Type.NamedType
if typeName == "" {
// For list types, get the element type name
if field.Type.Elem != nil {
typeName = field.Type.Elem.NamedType
}
}

// If the field is an input object type, recursively collect
if fieldDef, ok := schema.Types[typeName]; ok && fieldDef.IsInputType() {
collectInputObjectFields(fieldDef, schema, usedTypes)
if typeName != "" {
usedTypes[typeName] = true
// If field is an input object type, collect recursively
if fieldDef, ok := schema.Types[typeName]; ok && fieldDef.IsInputType() {
collectInputObjectFields(fieldDef, schema, usedTypes)
}
}
}
}
Expand Down

0 comments on commit fd37f93

Please sign in to comment.