Graphql-code-generator: ... on FragmentName incorrect types

Created on 4 Mar 2019  路  2Comments  路  Source: dotansimha/graphql-code-generator

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

bug plugins waiting-for-release

All 2 comments

@zenVentzi Fixed in the refactor we are doing now: https://github.com/dotansimha/graphql-code-generator/pull/1353 .

Fix available in 1.0.0 馃憤

Was this page helpful?
0 / 5 - 0 ratings

Related issues

mszczepanczyk picture mszczepanczyk  路  3Comments

jackhkmatthews picture jackhkmatthews  路  3Comments

rogerg93 picture rogerg93  路  3Comments

NickClark picture NickClark  路  3Comments

iamdanthedev picture iamdanthedev  路  3Comments