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

Federation plugin does not import autobind and generated models #2326

Closed
Orbsynated opened this issue Aug 17, 2022 · 1 comment · Fixed by #2594
Closed

Federation plugin does not import autobind and generated models #2326

Orbsynated opened this issue Aug 17, 2022 · 1 comment · Fixed by #2594

Comments

@Orbsynated
Copy link

Orbsynated commented Aug 17, 2022

What happened?

When using the federation plugin with the @entityResolver(multi: true) directive, the entity's input struct is created in the generated models file.
If the generated models are located not in the same package as the federation package, we get an undeclared name error, as the generated federation file does not import the models.

What did you expect?

When generating the federation file, it should include the generated models import and the autobind imports if needed.

Minimal graphql.schema and models to reproduce

Schema:

type MultiHello @key(fields: "name") @entityResolver(multi: true) {
    name: String!
}

Generated input struct in models_gen.go:

type MultiHelloByNamesInput struct {
	Name string `json:"ID"`
}

versions

  • go run github.com/99designs/gqlgen version v0.17.13
  • go version 1.17.9
@Orbsynated
Copy link
Author

bump

erankor added a commit to erankor/gqlgen that referenced this issue Mar 27, 2023
fixes 99designs#2326 - when using `@entityResolver(multi: true)` the InputType of
the entity resolver may be in a different package (usually `model`).
The fix is to pull the types.Type of the resolver input, and use
templates.CurrentImports.LookupType in order to render it correctly
(possibly adding another import)
StevenACoffman pushed a commit that referenced this issue Mar 28, 2023
* EntityResolver input type fix

fixes #2326 - when using `@entityResolver(multi: true)` the InputType of
the entity resolver may be in a different package (usually `model`).
The fix is to pull the types.Type of the resolver input, and use
templates.CurrentImports.LookupType in order to render it correctly
(possibly adding another import)

* entityResolver input type fix: update tests

change testdata/entityresolver/gqlgen.yml to use a dedicated package for
the model (as in the default sample yml), and run go generate.

before the input type fix, generation fails with errors like -
plugin/federation/testdata/entityresolver/generated/federation.go:338:17:
  undeclared name: MultiHelloByNamesInput
plugin/federation/testdata/entityresolver/generated/federation.go:354:21:
  undeclared name: MultiHelloMultipleRequiresByNamesInput
plugin/federation/testdata/entityresolver/generated/federation.go:362:17:
  undeclared name: MultiHelloMultipleRequiresByNamesInput
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.

1 participant