jkrajniak / graphql-codegen-go

Generate Go structs from graphql schema
MIT License
23 stars 3 forks source link

GraphQL Union Types #5

Closed jordanfowler closed 1 year ago

jordanfowler commented 1 year ago

After generating my Go code, everything works as expected except for GraphQL Union Types. Here's an example of a GraphQL union type:

#...
union FooType = Bar | Baz

type Foo {
  type: FooType
}
#...

The Go code being generated emits:

type Foo struct {
  Bar
  Baz
}

In the case where Bar and Baz have overlapping field names (likely the case), the Go compiler complains the struct fields for Bar and Baz repeat (as expected). I can certainly understand why this would be a challenge in Go, since you can't assign a struct field more than one type; one would need to use an interface in this case.

Perhaps the warning is just that and I don't need to worry about it?

jordanfowler commented 1 year ago

Should have read your README more thoroughly, I see you note on this.