Deduplication of inline fragments of interface implementations #8466
Answered
by
filiplikavcan
filiplikavcan
asked this question in
Q&A
-
Is it possible to configure typescript-operations plugin somehow so it deduplicates inline fragments of interface implementations? See the example bellow where type of PS: Schema is just an example. Nobody wants a vehicle with either engine or window and nothing else. ;) codegen.yaml: generates:
./types.ts:
plugins:
- typescript-operations schema and query: schema {
query: Query
}
type Query {
vehicle: Vehicle!
}
interface Part {
id: Int!
}
type Engine implements Part {
id: Int!
fuel: String!
}
type Window implements Part {
id: Int!
size: String!
}
interface Vehicle {
id: Int!
part: Part!
}
type Car implements Vehicle {
id: Int!
part: Part!
}
type Train implements Vehicle {
id: Int!
part: Part!
}
# query
query {
vehicle {
part {
id
...on Engine {
fuel
}
...on Window {
size
}
}
...on Car {
id
}
...on Train {
id
}
}
} types.ts: export type Unnamed_1_QueryVariables = Exact<{ [key: string]: never }>;
export type Unnamed_1_Query = {
__typename?: "Query";
vehicle:
| {
__typename?: "Car";
id: number;
part:
| { __typename?: "Engine"; fuel: string; id: number }
| { __typename?: "Window"; size: string; id: number };
}
| {
__typename?: "Train";
id: number;
part:
| { __typename?: "Engine"; fuel: string; id: number }
| { __typename?: "Window"; size: string; id: number };
};
}; |
Beta Was this translation helpful? Give feedback.
Answered by
filiplikavcan
Oct 11, 2022
Replies: 1 comment
-
export type Unnamed_1_Query = (
{
vehicle: (
{
id: number, part: (
{ fuel: string, id: number }
& { __typename?: 'Engine' }
) | (
{ size: string, id: number }
& { __typename?: 'Window' }
)
}
& { __typename?: 'Car' | 'Train' }
)
}
& { __typename?: 'Query' }
); |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
charlypoly
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
mergeFragmentTypes: true
helps to reduce the code size: