Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Reload config packages after generating models
If models are generated in a package that has already been loaded, and that package refers to another package that has already been loaded, we can find ourselves in a position where it appears that a GQL `union` is not satisfied. For example, if we have: ``` union Subject = User ``` with this gqlgen.yml in github.com/wendorf/gqlgen-error/gql: ``` schema: - schema.graphql exec: filename: generated.go model: filename: models_gen.go models: User: model: github.com/wendorf/gqlgen-error/gql.User Subject: model: github.com/wendorf/gqlgen-error/models.Subject ``` Note that our User model is in the github.com/wendorf/gqlgen-error.gql package, and our models_gen.go will be generated in that same package. When we try to run gqlgen, we get this error: ``` merging type systems failed: unable to bind to interface: github.com/wendorf/gqlgen-error/gql.User does not satisfy the interface github.com/wendorf/gqlgen-error/models.Subject ``` Digging deeper, it's because we use types.Implements in codegen/interface.go, which does a shallow object comparison. Because the type has been reloaded, it refers to a _different_ interface type object than the one we're comparing against, and get a false negative. By clearing the package cache and repopulating it, the whole package cache is generated at the same time, and comparisons across packages work. To see a demo of this, check out https://github.com/wendorf/gqlgen-error and try the following: 1. Checkout the works-with-v0.10.2 branch and `go generate ./...` to see that it works 2. Checkout the breaks-with-v0.13.0 branch (or run go get github.com/99designs/gqlgen@v0.13.0 yourself) and `go generate ./...` to see errors 3. Checkout the works-with-pull-request branch and `go generate ./...` to see that it works again. This branch adds a go.mod replace directive to use the gqlgen code in this PR. The demo starts at v0.10.2 since it is the last release without this problem. #1020 introduces the code that fails in this scenario.
- Loading branch information