Khan / genqlient

a truly type-safe Go GraphQL client
MIT License
1.07k stars 107 forks source link

feat: allow imports from same generated package #289

Closed avinassh closed 7 months ago

avinassh commented 1 year ago

This is a small change, but it lets you import marshaler and unmarshalers from the same generated package.

Why? I'd like to keep all the graphql related code into one. Following the conventions of the genqlient/example, I would like to keep a custom marshaler in the same directory as example. For e.g., example/helper.go could contain:

// helper.go
func UnMarshalDateTime(b []byte, v *time.Time) error {
    ...
    return nil
}

But following won't work:

...
generated: generated.go
package: main
bindings:
  DateTime:
    type: time.Time
    unmarshaler: "https://github.com/Khan/genqlient/main.UnMarshalDateTime" // since package name is main
    # unmarshaler: "https://github.com/Khan/genqlient/example.UnMarshalDateTime" // nor this, if one is using a custom package

So, instead I would like to add a new feature where one can import from the same package:

...
generated: generated.go
package: main
bindings:
  DateTime:
    type: time.Time
    unmarshaler: "main.UnMarshalDateTime"

What do you think? If you think this is good, then I will add tests and update the documentation

I have:

benjaminjkraft commented 7 months ago

Closing in favor of #316,

avinassh commented 7 months ago

Hey @benjaminjkraft I missed the previous notification. I checked #316 and I think its in the right direction 👍