99designs / 99designs/gqlgen

proposal: Federation plugin: combination of `explicit_requires` with entity multi-resolver works as not expected

Open
#3,089 1 comment 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?
Suppose you have an entity type, and your subgraph adds field to it - some function, that `@requires` other `@external` field in this entity. If you turn on `federation:options:explicit_requires: true` in your `gqlgen.yml`, it will generate `FindMany...` entity resolver. But will not generate `federation.requires.go` file with resolving `@requires` fields. However, it just fills all nested `@requires` fields in `federation.go` generated code, so, it will cause panic, if some nested fields in `@requires` are optional/mutually exclusive.

### What did you expect?
Generating `federation.requires.go` with `Populate...` method, that takes list of entities and reps map as an argument.

### Minimal graphql.schema and models to reproduce

In this example, to process `getHeroWithWeapon`, we need both `importantInfo` and fields in `@requires`:
```
type Hero @key(fileds: "id") @entityResolver(multi:true){
id: ID!
weapon: Weapon @external
getHeroWithWeapon(
importantInfo: SomeHeroInfo!
): DangerousHero @requires(fields: "weapon { id slug }")
}

type Weapon @shareable{
// we can identify weapon by ID OR Slug:
id: ID
slug: String
}
```
### versions
- `go run github.com/99designs/gqlgen version`?

`v0.17.45`
- `go version`?

`go version go1.21.8 darwin/arm64`

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.