Khan / genqlient

a truly type-safe Go GraphQL client
MIT License
1.03k stars 99 forks source link

feat: support binding to generated package #285

Closed costela closed 5 months ago

costela commented 1 year ago

This allows one to generate code in an existing package without causing import loops.

It is now possible to use something like the following (assuming we're in module github.com/foo/bar):

generated: generated/genqlient.go
package_bindings:
  - github.com/foo/bar/generated

or (shorthand variant of the example above)

generated: generated/genqlient.go
package_bindings:
  - .

or

generated: generated/genqlient.go
bindings:
  Bar:
    type: github.com/foo/bar/generated.Bar

The last example assumes some file in generated/ defines the type Bar.

Closes #283

benjaminjkraft commented 5 months ago

Closing in favor of #316 which makes this as a narrower change to support existing syntax. If you're interested, you could revisit adding the shorthand (package_bindings: . etc.); I think doing that separately will make some of the still-questions about what syntax we should support clearer.