gqlgen icon indicating copy to clipboard operation
gqlgen copied to clipboard

struct field is created even though `forceResolver: true`

Open quinn-freshly opened this issue 3 years ago • 2 comments

What happened?

I added @goField(forceResolver: true) to a field. As expected, a new resolver was added, but a field was also added to the struct in models_gen.go.

What did you expect?

I expected for only the resolver to be created. Since that field is not being resolved as part of the struct i expected no field to be added to the struct.

Minimal graphql.schema and models to reproduce

type User {
  friends: [User!]! @goField(forceResolver: true)
}

versions

  • gqlgen version?
github.com/99designs/gqlgen v0.13.0 h1:haLTcUp3Vwp80xMVEg5KRNwzfUrgFdRmtBY8fuB8scA=
github.com/99designs/gqlgen v0.13.0/go.mod h1:NV130r6f4tpRWuAI+zsrSdooO/eWUv+Gyyoi3rEfXIk=
  • go version?
go version go1.15.6 linux/amd64
  • dep or go modules? go mod

quinn-freshly avatar May 21 '21 15:05 quinn-freshly

Just ran into this, and was also confused. What is the expected behavior here?

burdiyan avatar Oct 05 '21 20:10 burdiyan

Saw this behaviour too. There are valid use cases though. The value can be populated in a parent resolver and you can use the existing value (sometimes).

I think another property to exclud the field would be reasonable to not cause mass breakages.

E.g.

@goField(forceResolver: true, omitField: true)

cliedeman avatar Nov 10 '21 12:11 cliedeman