We're using graphql-codegen
for generating types for graphql operations.
On our schema we have 50+ types that implement a common base interface Item
.
Example: All types implement Item
:
type Query {
datasource(value: String!): Item
}
interface Item {
name: String!
}
type TypeA implements Item {
name: String!
other: String!
}
type TypeB implements Item {
name: String!
somethingElse: String!
}
type TypeC implements Item {
name: String!
}
Example Query:
query MyData($datasource: String!) {
datasource(value: $datasource) {
... on TypeA {
name
other
}
}
}
When generating Typescript with the typescript-operations
plugin, we end up with types that look like this:
export type MyDataQuery = {
__typename?: 'Query';
datasource?:
| { __typename?: 'TypeA'; name: string; other: string }
| { __typename?: 'TypeB' } # <!-- not needed
| { __typename?: 'TypeC' } # <!-- not needed
| null
| undefined;
};
Notice TypeB and TypeC are also included as options. This leads to huge generated types with our 50+ types inheriting Item
.
Is there a way to specify exactly what type should be used (possibly in the Query?) instead of having all types that inherit Item
generated?