99designs / 99designs/gqlgen

End resolvers - ideas?

Aperta
#2,613 2 commenti 1 reazione 0 assegnatari Vedi su GitHub
Lingua principale
Go
Stelle
10.8k
Fork
1.3k
Merge medio
2g 36m
PR unite (30g)
26

Descrizione

Hi all, I have an interestng problem that I cannot easily solve. I'll use the example from gqlgen to explain it.

We have list of TODOs, users are loaded on-demand (see [here](https://gqlgen.com/getting-started/#dont-eagerly-fetch-the-user)). In our workflow, we always load users concurrently with dataloaders, it's super useful.

Let's say that these users have also a status flag and we don't want to show TODOs of users that are disabled.

How can we do that?

The problem is that we can handle and change TODO slice in `Todos(ctx context.Context)` before TODOs are returned to gqlgen. But we know nothing about Users there yet. gqlgen takes those TODOs, glues User to every one and returns the result. We could load User data in Todos() function, but this would load them seqentially and not concurrently like dataloader does.

If gqlgen had an end resolver (of final resolver, or whatever name) which would be run after field resolvers are done, we could then filter TODOs based on those User objects.

----

This would tell gqlgen to create an "end" resolver:

```
models:
ID:
...
Todo:
fields:
user:
resolver: true
resolver: true // <-- this
```
an generate a method something like:

```
func (r *todoResolver) End(ctx context.Context, obj []*model.Todo) ([]*model.Todo, error) {
// do whatever we need with TODO and it's User
return obj, nil
}
```

Thoughts?

Guida per i contributori

Apri la guida per i contributori

Valutazione

Questa issue non è ancora stata valutata.

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.