Open maaft opened 3 years ago
The actual model generation which includes the interface/implementation generation is performed by https://github.com/99designs/gqlgen.
Would be good to open an issue there first.
Also, you should re-write your example above because it is hard to understand, here a fixed one:
interface Foo {
value: String!
}
type FooA implements Foo {
bla: String!
value: String!
}
type FooB {
blub: String!
value: String!
}
type Foo interface {
IsFoo()
GetValue() string
}
type FooA struct {
Bla string
Value string
}
func (f FooA) IsFoo() {}
func (f FooA) GetValue() string {
return f.Value
}
type FooB struct {
Blub string
Value string
}
func (f FooB) IsFoo() {}
func (f FooB) GetValue() string {
return f.Value
}
The getters will need to have the prefix Get
since a function on a struct and a field on struct can't have the same name.
Thanks for pointing out that this is done by 99designs/gqlgen. I'll open an issue there.
Also thanks for pointing out that we'd need a prefix like "Get". You're absolutely right. Regarding your schema, you don't need to redeclare interface fields on impementing types.
for reference: https://github.com/99designs/gqlgen/issues/1469
When you have this schema:
it would be great if you could generate getter functions for all fields on the interface.
This would allow to read all common fields directly from the interface instead of doing a typeswitch.