Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
MikhailLipanin opened this issue May 22, 2024 · 1 comment · May be fixed by #3115

Comments

@MikhailLipanin
Copy link

MikhailLipanin commented May 22, 2024

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

@MikhailLipanin MikhailLipanin changed the title Federation plugin: combination of explicit_requires with entity multi-resolver works as not expected proposal: Federation plugin: combination of explicit_requires with entity multi-resolver works as not expected Jun 2, 2024
MikhailLipanin added a commit to MikhailLipanin/gqlgen that referenced this issue Jun 2, 2024
@MikhailLipanin MikhailLipanin linked a pull request Jun 2, 2024 that will close this issue
2 tasks
@clayne11
Copy link
Contributor

I'm working on this as well as an improved @requires API. Hoping to have a PR up in the next week.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants