score:3

Accepted answer

How about doing it like this:

const userFragment = gql`
  fragment Relationship_user on User {
    ...User_user
  }
  ${User.fragments.user}
`;
Relationship.fragments = {
  user1: userFragment,
  user2: userFragment,
};

Apart from that, I'd recommend you scope your fragment names as shown above, as some kind of name spacing is required, because otherwise it's more likely you'll run into using the same fragment names twice.

i.e.

  • User.fragments.user => User_user
  • Relationship.fragments.user => Relationship_user

Related Query

More Query from same tag