99designs / 99designs/gqlgen

How do I pass values from Directive to Resolver through context?

Aberta
#2,855 3 comentários 0 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?

```
c.Directives.Test = func(ctx context.Context, obj interface{}, next graphql.Resolver, key *string) (interface{}, error) {

ctx = context.WithValue(ctx, resolver.ContextKey, 11)
fmt.Printf("Context address in Resolver: %p\n", &ctx)

return next(ctx)
}
```

### What did you expect?

I hope to be able to get the value through Context during Resolver, But

By reading the source code, I found that the Directive's Context was created by
```graphql.WithPathContext(ctx, graphql.NewPathWithField("fieldName")) ```
and this context was only used to return errors and was not passed to the Resolver. I tried to modify generated!. gotpl file, but the configuration file cannot modify the path of this template

### Minimal graphql.schema and models to reproduce

### versions
- `go run github.com/99designs/gqlgen version`? v0.17.40
- `go version`? 1.21.5

Guia de contribuição

Abrir o guia de contribuição

Avaliação

Esta issue ainda não foi avaliada.

Receba novas issues na sua caixa de entrada

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