99designs / 99designs/gqlgen

Alias types are not referred as alises in the resolver

Aberta
#3,265 0 comentários 3 reações 0 responsáveis Ver no GitHub
Linguagem predominante
Go
Estrelas
10.8k
Forks
1.3k
Merge médio
2d 36min
PRs com merge (30d)
26

Descrição

### What happened?

When referring an alias type in the models section of the `gqlgen.yml` and running `go run github.com/99designs/gqlgen generate` I get an error if the aliased type has implementations that are not exported.

### What did you expect?

I expect it to use the alias reference, and not the underlying type.

### Minimal graphql.schema and models to reproduce

**schema.graphql**
```
scalar IDXID

type Query {
id: IDXID!
}
```

**gqlgen.yml**
```
models:
IDXID:
model:
- gqltest/pkg/identifier.IDXID
```

**id.go**

```
import ("io")

type i struct{}
func (i i) Prefix() string { return "i" }
type IDXID = ID[i]
type Prefixer interface {
Prefix() string
}
type ID[T Prefixer] struct{}
func (id *ID[T]) UnmarshalGQL(v interface{}) error { return nil }
func (id ID[T]) MarshalGQL(w io.Writer) {}
```

With the implementation above it returns:

>validation failed: packages.Load: -: # gqltest/graph
graph/generated.go:55:53: i not exported by package identifier
graph/generated.go:271:43: i not exported by package identifier
graph/generated.go:2612:139: i not exported by package identifier
graph/generated.go:2613:35: i not exported by package identifier
graph/generated.go:2618:145: i not exported by package identifier
graph/generated.go:2622:143: i not exported by package identifier
graph/generated.go:2623:41: i not exported by package identifier
graph/generated.go:2628:149: i not exported by package identifier
graph/schema.resolvers.go:14:76: i not exported by package identifier

If I make the reference exportable (change `i` to `I`), it works but the resolver looks like:

```
// ID is the resolver for the id field.
func (r *queryResolver) ID(ctx context.Context) (*identifier.ID[identifier.I], error) {
panic(fmt.Errorf("not implemented: ID - id"))
}
```

So it uses the `identifier.ID[identifier.I]` instead of `identifier.IDXID`

I would like for gqlgen to use the aliases I have defined and imported

### versions
- Latest version (master branch)
- Tried both Go 1.22.5 and 1.23.0

Guia de contribuição

Abrir o guia de contribuição

Direção de pesquisa

The issue is in the code generation for alias types. Look at the resolver generation code, likely in `graph/generated.go` and `graph/schema.resolvers.go`. The bug is that the generated code references the underlying generic type `identifier.ID[identifier.I]` instead of the alias `identifier.IDXID`. Start by examining how models are mapped in `gqlgen.yml` and how the codegen handles aliases. Check the `models` package or configuration parsing. The fix should ensure the alias type is used in the resolver signature. Run the provided minimal example to reproduce the error.

Escrita pelo modelo de indexação a partir do texto da issue.

Avaliação

Stack de tecnologia
go, graphql
Domínio
api, backend
Tipo de issue
Bug
Dificuldade
3/5
Tempo estimado
1-2 dias
Status de atividade
Estagnada
Clareza
Claramente especificada
Facilidade para iniciantes
45/100

Receba novas issues na sua caixa de entrada

Um resumo curto de issues do GitHub para quem está começando.