99designs / 99designs/gqlgen

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

Open
#2,855 3 comments 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?

```
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

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.