apollographql / apollo-ios

📱  A strongly-typed, caching GraphQL client for iOS, written in Swift.
https://www.apollographql.com/docs/ios/
MIT License
3.89k stars 728 forks source link

Codegen: Merging entity into same type with inclusion condition does not build #3426

Open calvincestari opened 3 months ago

calvincestari commented 3 months ago

Found this edge case when working on https://github.com/apollographql/apollo-ios/issues/3424.

Schema

type Query {
  allThings: [Thing!]
}

type Thing {
  name: String
  postsInfoByIds: [PostInfo!]
}

interface PostInfo {
  awardings: [AwardingTotal!]
}

type Awarding {
  id: String!
}

type AwardingTotal {
  id: String!
  awardingByCurrentUser: [Awarding!]
  total: Int!
}

type Post implements PostInfo {
  id: String!
  awardings: [AwardingTotal!]
}

Operation

query AllThings_inverted($includeCurrentUserAwards: Boolean = false) {
  allThings {
    name
    postsInfoByIds {
      ... on Post {
        awardings @include(if: $includeCurrentUserAwards) {
          total
        }
      }
      awardings {
        awardingByCurrentUser {
          id
        }
      }
    }
  }
}

Expected: The target node should have a type Awarding without a condition and the merged in field (awardingByCurrentUser) and then a conditional case (IfIncludeCurrentUserAwards) within it that contains the conditional field (total).