Open joeried opened 1 year ago
I'm experiencing similar things.
#This schema is as same as joeried's one
interface TestInterface implements Node{
id: ID!
fieldA: String!
}
type TypeWithFieldB implements Node & TestInterface {
id: ID!
fieldA: String!
fieldB: String!
}
type TypeWithFieldC implements Node & TestInterface {
id: ID!
fieldA: String!
fieldC: String!
}
fragment Test4 on TestInterface {
__typename
... on TypeWithFieldB {
fieldA
fieldB
}
... on TypeWithFieldC {
fieldA
fieldC
}
}
The resulting type after executing the above query is as follows:
type TestQueryResult = {
readonly __typename: string;
}
I hope to be of the following type:
type TestQueryResult = {
readonly __typename: "TypeWithFieldB" | "TypeWithFieldC";
}
@captbaritone Are there any plans to fix this issue?
Hello,
I have a case here where the typescript types generated by the relay-compiler look wrong to me.
Let's say I've got the following schema
Example 1 (which works like I would expect it)
If I now create a fragment like this
Then the generated types look good
Example 2 (Wrong __typename)
If I create a fragment like this (fieldA pulled to the top):
Then the generated types look like this:
While the type itself looks like a sensible merge of TypeWithFieldB and TypeWithFieldC the __typename should probably not be "TypeWithFieldB".
Example 3 (Wrong __typename caused by refetchable fragment)
Then the generated types look like in Example 2. What is surprising to me here is that the fragment structure is chosen exactly as in the working example 1 with the only difference that here the fragment is marked as refetchable.
Repo with example code: https://github.com/joeried/relay-compiler-issue-repro/
If I'm not mistaken, then the generated types are just wrong, or am I mistaken? Is there a way to get types that are structured more like the ones in Example 1?