gqlgen generates non compilable federation.go code when schema uses @requires directive with attribute referring inside array for dependency
#2,632 opened on May 10, 2023
Repository metrics
- Stars
- (10,737 stars)
- PR merge metrics
- (PR metrics pending)
Description
What happened?
gqlgen generates non compilable code when schema has uses @requires directive with array nested attribute dependency for federation. in federation.go file i.e. see the sample schema that is mentioned below
What did you expect?
It should generate compilable code
Minimal graphql.schema and models to reproduce
type Query {
reviews(bookID: ID!): [Review]
}
type Book @key(fields: "id", resolvable: false ) {
id: ID! @external
publishers:[Publishers] @external
reviews: [Review] @requires(fields: "publishers {name}" )
}
type Publishers @key(fields: "id", resolvable: false) {
id: ID! @external
name: String @external
}
type Review @key(fields: "id") {
id: ID! @external
name: String
}
versions
go run github.com/99designs/gqlgen version? v0.17.31go version? go1.20.3 darwin/amd64
if you try to run ----
it will generate error validation failed: packages.Load: /graph/generated/federation.go:100 : 23: entity.Publishers.Name undefined (type []*model.Publishers has no field or method Name)
on this line in federation.go file
entity.Publishers.Name, err = ec.unmarshalOString2ᚖstring(ctx, rep["publishers"].(map[string]interface{})["name"])
This is because Publishers.Name is incorrect ... Publishers is array