Code Generation Fails When Binding Types: "Unable to Bind to Interface #2835
islamaliev
started this conversation in
General
Replies: 1 comment
-
You need to implement the interface methods. Example I had this interface
I had to add this to my object
|
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hello gqlgen community,
I'm facing a perplexing issue with gqlgen's code generation in my Go project. I have a GraphQL schema and a Go interface, and I'm trying to bind a GraphQL type
CourseProduct
to a Go struct. However, I'm encountering an error during the code generation process that I can't seem to resolve.GraphQL Schema:
I have a Go interface defined in
internal/service/product/model/product.go
:I also have wrapper structs in different packages:
CourseWrapper1
ininternal/service/product
CourseWrapper2
ininternal/service
Both wrappers embed
*model.Course
.When I run
go generate ./...
, the code generation fails with the following error:Interestingly, if I bind
CourseProduct
toproject.com/internal/service/product.CourseWrapper1
(which is essentially the same struct but one package closer tomodel.Product
), the error disappears.Additional Observation:
If I comment out the
GetCreatedAt() time.Time
method in themodel.Product
interface, the code generates successfully even when binding toproject.com/internal/service.CourseWrapper2
.I've tried debugging this issue, but it goes deep into
go/types
,golang.org/x/tools/go/packages/packages.go
, and other internals of how Go loads and resolves packages and types.I've also posted this question on Stack Overflow for additional visibility.
Any insights or suggestions would be greatly appreciated!
Beta Was this translation helpful? Give feedback.
All reactions