Skip to content

generate panic when @requires with a union is being used #3608

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

Open
grzn opened this issue Mar 22, 2025 · 4 comments
Open

generate panic when @requires with a union is being used #3608

grzn opened this issue Mar 22, 2025 · 4 comments

Comments

@grzn
Copy link

grzn commented Mar 22, 2025

We have something like this in our schema

extend type SomeType @key(fields: "id") {
  id: ID! @external
  someField @requires(fields: "anotherField { unionField { ... on typeA { field1 } } }")
}

when we add unionField to requires then go run github.com/99designs/gqlgen generate panics:

federation: template.gotpl: template: template.gotpl:199:54: executing "template.gotpl" at <.Type.UnmarshalFunc>: error calling UnmarshalFunc: runtime error: invalid memory address or nil pointer dereference
@grzn
Copy link
Author

grzn commented Mar 22, 2025

hmmm, not sure why yet, and if its works as expected in rutime, but with

options:
  explicit_requires: true

generate works.

@grzn
Copy link
Author

grzn commented Mar 22, 2025

with computed_requires it works as well; closing

@grzn grzn closed this as completed Mar 22, 2025
@grzn grzn reopened this Mar 23, 2025
@grzn
Copy link
Author

grzn commented Mar 23, 2025

Reopening, because when adding __typename is panics:

extend type SomeType @key(fields: "id") {
  id: ID! @external
  someField @requires(fields: "anotherField { unionField { __typename ... on typeA { field1 } } }")
}
go run github.com/99designs/gqlgen
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x30 pc=0x7ffbbc]

goroutine 1 [running]:
github.com/99designs/gqlgen/plugin/federation/fieldset.fieldByName(0xa43cd0?, {0xc00030ab6c, 0xa})
	/go/pkg/mod/github.com/99designs/gqlgen@v0.17.64/plugin/federation/fieldset/fieldset.go:191 +0x1c
github.com/99designs/gqlgen/plugin/federation/fieldset.Field.TypeReference({0xc0003ffc40, 0x3, 0xc0422b8740?}, 0x3c?, {0xc007879688, 0x63, 0xc?})
	/go/pkg/mod/github.com/99designs/gqlgen@v0.17.64/plugin/federation/fieldset/fieldset.go:78 +0x8b
github.com/99designs/gqlgen/plugin/federation.(*Federation).GenerateCode(0xc0002d1e90, 0xc000189290)
	/go/pkg/mod/github.com/99designs/gqlgen@v0.17.64/plugin/federation/federation.go:286 +0xe36
github.com/99designs/gqlgen/api.Generate(0xc0001e3448, {0x0, 0x0, 0xed4c40?})
	/go/pkg/mod/github.com/99designs/gqlgen@v0.17.64/api/generate.go:122 +0xd51
main.init.func2(0xc0000cae80?)
	/go/pkg/mod/github.com/99designs/gqlgen@v0.17.64/main.go:190 +0x9f
github.com/urfave/cli/v2.(*Command).Run(0xc0001e46e0, 0xc0000cae80, {0xc0000220b0, 0x1, 0x1})
	/go/pkg/mod/github.com/urfave/cli/v2@v2.27.5/command.go:276 +0x7be
github.com/urfave/cli/v2.(*App).RunContext(0xc00019a600, {0xaf0c70, 0xf11a40}, {0xc0000220b0, 0x1, 0x1})
	/go/pkg/mod/github.com/urfave/cli/v2@v2.27.5/app.go:333 +0x5a5
github.com/urfave/cli/v2.(*App).Run(...)
	/go/pkg/mod/github.com/urfave/cli/v2@v2.27.5/app.go:307
main.main()
	/go/pkg/mod/github.com/99designs/gqlgen@v0.17.64/main.go:227 +0x20b
exit status 2

@StevenACoffman
Copy link
Collaborator

Have you tried it with latest gqlgen and found it still occurs? There were a few changes that might fix your problem.

If the problem still occurs with the latest version, do you have a public repository where I can attempt to re-create this problem? I'm not able to help much when I can't

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

No branches or pull requests

2 participants