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
Foo and Bar have case class fields for __typename, which means that we have to request __typename in the query for both of them or the decoding will fail for no good reason. It would make more sense to generate constants, since we already know the value anyway and it never changes.
// Instead ofcaseclassFoo(__typename: String, slug: String)
// we should generatecaseclassFoo(slug: String) {
def__typename:String="Foo"
}
// or maybe evencaseclassFoo(slug: String) {
def__typename:String=Foo.__typename
}
objectFoo {
def__typename:String="Foo"
}
Inside of Bar we reference Foo for the second union case in the query. In the generated code we have a dedicated Bar.Foo generated but for some dumb reason, we use Content.Foo in Bar and Bar.Foo is unused. This means the whole thing doesn't work if the two cases use different fields from Foo.
I'm not sure if there is a reason for this (fragments?) or if it's just an honest mistake.
Not really a bug but strange: The implementation for Encoder[Content] derives encoders inline instead of using the existing ones. The equivalent Decoder doesn't do this. Imo we shouldn't derive something inline, especially if it already exists.
The text was updated successfully, but these errors were encountered:
I have spent several hours to get my head around code gen for union types in #79 ... without success so far 😢
The best workaround at this point is to use the codgen directive introduced in #93 .
However we may fail the codegen if __typename is missing in the query document for a union type. Or add it and issue a warning. That at least safe guards for this scenario.
I'll just document this here, sadly I don't have the time to fix it right now.
Version used: 0.16.4
Given the following query:
The generated code looks like this (only the relevant part):
There are two bugs here:
Foo
andBar
have case class fields for__typename
, which means that we have to request__typename
in the query for both of them or the decoding will fail for no good reason. It would make more sense to generate constants, since we already know the value anyway and it never changes.Inside of
Bar
we referenceFoo
for the second union case in the query. In the generated code we have a dedicatedBar.Foo
generated but for some dumb reason, we useContent.Foo
inBar
andBar.Foo
is unused. This means the whole thing doesn't work if the two cases use different fields fromFoo
.I'm not sure if there is a reason for this (fragments?) or if it's just an honest mistake.
Not really a bug but strange: The implementation for
Encoder[Content]
derives encoders inline instead of using the existing ones. The equivalentDecoder
doesn't do this. Imo we shouldn't derive something inline, especially if it already exists.The text was updated successfully, but these errors were encountered: