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 730 forks source link

Schema type renaming not working with @include directive #3456

Closed BobaFetters closed 1 month ago

BobaFetters commented 1 month ago

Issue reported in this thread https://graphchampions.slack.com/archives/C02L9FDUZKM/p1727826399718149 it appears that types that have been renamed through the config option aren't using their new name for an @include directive usage.

From the original report:

I specified the following in my config:

"schemaCustomization" : {
            "customTypeNames" : {
              "CustomV2" : "CustomNew"
            }
        }

it works great for fields, and generates CustomNew interface: static let CustomNew = ApolloAPI.Interface(name: "CustomV2") However, in one of my queries, it skips to use the alias I want, when it’s wrapped in include directive:

static var __selections: [ApolloAPI.Selection] { [
      .field("__typename", String.self),
      .field("field1", Field1.self),
      .field("field2", GraphQL.Long.self),
      .include(if: "useCustomV2", .field("customV2", CustomV2.self)),
     ] }

I’d expect:

static var __selections: [ApolloAPI.Selection] { [
      .field("__typename", String.self),
      .field("field1", Field1.self),
      .field("field2", GraphQL.Long.self),
      .include(if: "useCustomV2", .field("customV2", CustomNew.self)),
     ] }
BobaFetters commented 1 month ago

The field in question is a Selection Set type and not a Schema type which is what the custom renaming is used for, this field would need to be renamed using a field alias in order to change its name. I have created an issue to add docs to help better explain this distinction here.

github-actions[bot] commented 1 month ago

Do you have any feedback for the maintainers? Please tell us by taking a one-minute survey. Your responses will help us understand Apollo iOS usage and allow us to serve you better.