Skip to content

Commit

Permalink
warn against self-binding circularity
Browse files Browse the repository at this point in the history
  • Loading branch information
benjaminjkraft committed Feb 18, 2024
1 parent 852b48c commit a9dba06
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
6 changes: 6 additions & 0 deletions docs/genqlient.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,9 @@ optional_generic_type: github.com/organisation/repository/example.Type
# guarantees that the fields requested in the query match those present in
# the Go type.
#
# Note: if binding to types in the same package as the generated code, make
# sure you don't bind to generated types! Otherwise, things get very circular.
#
# To get equivalent behavior in just one query, use @genqlient(bind: ...);
# see genqlient_directive.graphql for more details.
bindings:
Expand Down Expand Up @@ -228,6 +231,9 @@ bindings:
# to the bindings map, above, for each exported type in the package. Multiple
# packages may be specified, and later ones take precedence over earlier ones.
# Explicit entries in bindings take precedence over all package bindings.
#
# Note: make sure this isn't the package with your generated code, or things
# will get circular very fast.
package_bindings:
- package: github.com/you/yourpkg/models

Expand Down
5 changes: 5 additions & 0 deletions generate/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,11 @@ func (c *Config) ValidateAndFillDefaults(baseDir string) error {
binding.Package)
}

if binding.Package == c.pkgPath {
warn(errorf(nil, "warning: binding to the same package as your generated "+
"code ('%v'); this will probably cause circularity issues", c.pkgPath))
}

mode := packages.NeedDeps | packages.NeedTypes
pkgs, err := packages.Load(&packages.Config{
Mode: mode,
Expand Down

0 comments on commit a9dba06

Please sign in to comment.