From fd37f9386c9aaad86569d5d36cb8667bf80d563b Mon Sep 17 00:00:00 2001 From: Yamashou <1230124fw@gmail.com> Date: Tue, 3 Dec 2024 03:15:16 +0900 Subject: [PATCH] Fix infinity loop skip already exist type --- main.go | 2 +- querydocument/query_document.go | 25 ++++++++++++++++++++----- 2 files changed, 21 insertions(+), 6 deletions(-) diff --git a/main.go b/main.go index 842e9a4..a3849c9 100644 --- a/main.go +++ b/main.go @@ -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", diff --git a/querydocument/query_document.go b/querydocument/query_document.go index 35bff5b..943186a 100644 --- a/querydocument/query_document.go +++ b/querydocument/query_document.go @@ -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) + } } } }