Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix already exist type #248

Merged
merged 1 commit into from
Dec 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading