You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Improve package-sniffing and bind correctly to types in the same package (#316)
The original motivation here is to fix#283, which is that if you try to
use `bindings` to bind to a type in the same package as the generated
code, we generate a self-import, which Go doesn't allow. Fixing that is
easy -- the three lines in `imports.go` -- once you know the
package-path of the generated code. (The test that that all fits
together is in integration-tests because that was the easiest place to
set up the right situation.)
Determining the package-path is not too much harder: you ask
`go/packages`, which we already use for `package_bindings`. But once
we're doing that, and handling errors, it's kinda silly that we ask you
to specify the package your generated code will use, because we have
that too, usually. So I rewrote that handling too, making `package` now
rarely necessary (see for example the `example` config), and warning if
it looks wrong. This is the changes in `config.go`, and is the more
substantial non-test change. (I also renamed some of the testdata dirs
to be valid package-names, to exercise more of that code, or in the case
of `find-config`, just for consistency.)
I have:
- [x] Written a clear PR title and description (above)
- [x] Signed the [Khan Academy CLA](https://www.khanacademy.org/r/cla)
- [x] Added tests covering my changes, if applicable (and checked that
the test for the bugfix fails without the rest of the changes)
- [x] Included a link to the issue fixed, if applicable
- [x] Included documentation, for new features
- [x] Added ~an entry~ two entries to the changelog
Copy file name to clipboardExpand all lines: docs/CHANGELOG.md
+2Lines changed: 2 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -31,11 +31,13 @@ Note that genqlient is now tested from Go 1.20 through Go 1.22.
31
31
- The new `optional: generic` allows using a generic type to represent optionality. See the [documentation](genqlient.yaml) for details.
32
32
- For schemas with enum values that differ only in casing, it's now possible to disable smart-casing in genqlient.yaml; see the [documentation](genqlient.yaml) for `casing` for details.
33
33
- Support .graphqls and .gql file extensions
34
+
- More accurately guess the package name for generated code (and warn if the config option -- now almost never needed -- looks wrong).
34
35
35
36
### Bug fixes:
36
37
- The presence of negative pointer directives, i.e., `# @genqlient(pointer: false)` are now respected even in the when `optional: pointer` is set in the configuration file.
37
38
- Made name collisions between query/mutation arguments and local function variables less likely.
38
39
- Fix generation issue related to golang type implementation of complex graphql union fragments
40
+
- Bind correctly to types in the same package as the generated code.
0 commit comments