99designs / 99designs/gqlgen

usage of field resolver when it is used in multiple resolvers

Open
#1,448 5 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?
Followed this link https://github.com/99designs/gqlgen#using-explicit-resolvers to have field based resolvers so that they are fetched only when they are asked for.
```
Todo:
fields:
user:
resolver: true
```
Below is the model, and the two queries which returns this model.
```
type Todo {
id(version1: String!): ID! @directive1
text: String!
done: Boolean! @deprecated(reason: "some reason")
user: User!
}

type Query {
todos(version: String!): [Todo!]!
todos_ex(version: String!): [Todo!]!
}
```
On performing `go run github.com/99designs/gqlgen generate`, below is the resolver got added.
```
func (r *todoResolver) User(ctx context.Context, obj *model.Todo) (*model.User, error) {
```

But, I have a requirement to perform different operations in `User` `todoResolver` based on the type of query resolver which it is called.
Same model `Todo` might be returned in mutations as well.

It would be helpful if there are steps that I can do to achieve this.
### What did you expect?

I expected a seperate field resolver for each query/mutation/subscription resolver it is returned from (or) any other way to achieve this.

### Minimal graphql.schema and models to reproduce

### versions
- `gqlgen version`?
- `go version`?
go1.14.2
- dep or go modules?

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.