99designs / 99designs/gqlgen

Duplicate ComplexityRoot object names

Open
#1,531 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
Go
Stars
10.8k
Forks
1.3k
Avg merge
2d 36m
Merged PRs (30d)
26

Description

### What happened?

Duplicate ComplexityRoot object names

Error :

```
validation failed: packages.Load: /Users/akshaypatil/gqlgen-todos/graph/generated/generated.go:50:2: FooBar redeclared
/Users/akshaypatil/gqlgen-todos/graph/generated/generated.go:46:2: other declaration of FooBar
/Users/akshaypatil/gqlgen-todos/graph/generated/generated.go:98:26: e.complexity.FooBar.Dummy1 undefined (type struct{Dummy2 func(childComplexity int) int} has no field or method Dummy1)
/Users/akshaypatil/gqlgen-todos/graph/generated/generated.go:102:30: e.complexity.FooBar.Dummy1 undefined (type struct{Dummy2 func(childComplexity int) int} has no field or method Dummy1)
exit status 1
```

File: `generated.go`
```
type ComplexityRoot struct {
FooBar struct {
Dummy2 func(childComplexity int) int
}

FooBar struct {
Dummy1 func(childComplexity int) int
}

Mutation struct {
CreateTodo func(childComplexity int, input model.NewTodo) int
}

Query struct {
Todos func(childComplexity int) int
}

Todo struct {
FooBar func(childComplexity int) int
FooBarWithUnderscore func(childComplexity int) int
}
}
```

### What did you expect?

Object names in ComplexityRoot should be unique.

### Minimal graphql.schema and models to reproduce

File: `graph/schema.graphqls`
```
# GraphQL schema example
#
# https://gqlgen.com/getting-started/

type Todo {
fooBarWithUnderscore: Foo_Bar
fooBar: FooBar
}

type Foo_Bar {
dummy1: String
}

type FooBar {
dummy2: String
}

type Query {
todos: [Todo!]!
}

input NewTodo {
text: String!
userId: String!
}

type Mutation {
createTodo(input: NewTodo!): Todo!
}
```

File: `graph/model/types.go`
```
package model

type Foo_Bar struct {
Dummy1 *string `json:"dummy1"`
}

type FooBar struct {
Dummy2 *string `json:"dummy2"`
}
```

### versions
- `gqlgen version`?
v0.11.3
- `go version`?
go1.15.7
- dep or go modules?
go modules

Contributor guide

Open the contributing guide

Research direction

The issue is in the code generation for the ComplexityRoot struct in graph/generated/generated.go. Look at the gqlgen code that generates struct field names from GraphQL type names, focusing on how it handles underscores. The schema defines types 'Foo_Bar' and 'FooBar', which likely map to the same Go struct field name 'FooBar', causing a duplicate. Start by searching for the generator logic that maps GraphQL type names to Go identifiers. Verify the fix by running the provided schema through gqlgen and checking the generated code.

Written by the indexing model from the issue text.

Assessment

Tech stack
go
Domain
api, backend
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.