Describe the bug
The common fields are missing from the fragment type
Example:
export const GET_NEWSFEED = gql`
query Newsfeed {
newsfeed {
type
createdOn
... on AnswerNews {
performer {
...UserFields
}
question {
...QuestionFields
}
}
}
}
${UserFields}
${QuestionFields}
`;
export type NewsfeedNewsfeed = {
__typename?:
| NewsfeedAnswerNewsInlineFragment["__typename"]
| NewsfeedCommentNewsInlineFragment["__typename"]
| NewsfeedNewLikeNewsInlineFragment["__typename"]
| NewsfeedNewFollowerNewsInlineFragment["__typename"];
type: NewsType;
createdOn: DateTime;
} & (
| NewsfeedAnswerNewsInlineFragment
| NewsfeedCommentNewsInlineFragment
| NewsfeedNewLikeNewsInlineFragment
| NewsfeedNewFollowerNewsInlineFragment);
export type NewsfeedAnswerNewsInlineFragment = {
__typename?: "AnswerNews";
//here I need type and createdOn fields
performer: NewsfeedPerformer;
question: NewsfeedQuestion;
};
Logically the fragment ts type is correct but use-wise it's not very useful. For example, I still need to access createdOn and type fields, which is unavailable in the fragment type. Yes, I can start manually adding & {..* the fields missing * } but that is not very handy.
All the code and configurations are too long but the mistake that the gen is making is that it doesn't understand that type & createdOn are common fields for all the fragments below
@zenVentzi Fixed in the refactor we are doing now: https://github.com/dotansimha/graphql-code-generator/pull/1353 .
Fix available in 1.0.0 馃憤