apollo-ios icon indicating copy to clipboard operation
apollo-ios copied to clipboard

Codegen: `__mergedSources` on `asSomethingType` intermittently repeats then removed.

Open jimisaacs opened this issue 10 months ago • 8 comments

Summary

We have recently upgraded from 1.15.0 to 1.17.0, and I have seen the following behavior. I am calling this a bug report, but it might also be a request for confirmation that this behavior was identified and fixed already. I can't seem to repro right now so maybe it was 🤷.

If I have GraphQL schema like this:

type Query {
    something: MaybeSomething
}

interface MaybeSomething {
    darkside: Boolean
    complete: Boolean
}

type DefinitelySomething implements MaybeSomething {
    darkside: Boolean
    complete: Boolean
}

and a GraphQL operation like this:

query GetSomething {
    something {
        ...MaybeSomething
    }
}

fragment MaybeSomething on MaybeSomething {
    ...DefinitelySomethingFragment
    ...DefinitelySomethingSomethingFragment
}

fragment DefinitelySomethingFragment on DefinitelySomething {
    darkside
}

fragment DefinitelySomethingSomethingFragment on DefinitelySomething {
    complete
}

The codegen for GetSomethingQuery.graphql.swift will sometimes contain the following:

/* ... */
      public struct AsDefinitelySomething: MyMockSchema.InlineFragment, ApolloAPI.CompositeInlineFragment {
        /* ... */
        public static var __mergedSources: [any ApolloAPI.SelectionSet.Type] { [
          GetSomethingQuery.Data.Something.self,
          MaybeSomething.AsDefinitelySomething.self,
          DefinitelySomethingFragment.self,
          DefinitelySomethingSomethingFragment.self
        ] }
        /* ... */
      }
/* ... */

and sometimes it will contain the following instead:

/* ... */
      public struct AsDefinitelySomething: MyMockSchema.InlineFragment, ApolloAPI.CompositeInlineFragment {
        /* ... */
        public static var __mergedSources: [any ApolloAPI.SelectionSet.Type] { [
          GetSomethingQuery.Data.Something.self,
          MaybeSomething.AsDefinitelySomething.self,
          MaybeSomething.AsDefinitelySomething.self,
          DefinitelySomethingFragment.self,
          DefinitelySomethingSomethingFragment.self
        ] }
        /* ... */
      }
/* ... */

Notice the duplicate MaybeSomething.AsDefinitelySomething.self, versus it being absent. This is what happened intermittently after codegen, though I'm not sure if it was only for 1.15.0 and is potentially fixed now.

Version

Maybe 1.15.0, or maybe 1.17.0

Steps to reproduce the behavior

Run codegen repeatedly with the aforementioned GraphQL sources.

Logs


Anything else?

No response

jimisaacs avatar Feb 04 '25 16:02 jimisaacs

@jimisaacs Thanks for the report, I'll take a look and see if we've done anything that may have already fixed this, or work on trying to reproduce to see what the issue is.

BobaFetters avatar Feb 04 '25 17:02 BobaFetters

@jimisaacs So far have not been able to reproduce on 1.15.0 through 1.17.0, wondering if you could provide some more info:

  • What kind of machine are you seeing the issue on? Intel or Apple Silicon?
  • What macOS version?
  • What Xcode version?
  • When trying 1.17.0 did you disable fragment field merging? Thinking its possible turning that off would maybe bypass this issue.
  • Any guess about how how often you are seeing this? Like 1 in every 10 code gen runs for example

BobaFetters avatar Feb 05 '25 01:02 BobaFetters

Since we havn't been able to reproduce this going to go ahead and close this issue as it may have been fixed already. If you continue seeing the issue let us know and we can look into it again.

BobaFetters avatar Feb 14 '25 18:02 BobaFetters

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.

github-actions[bot] avatar Feb 14 '25 18:02 github-actions[bot]

Hello team, I'm still having this issue that @jimisaacs is describing.

  • Running on M4 Max
  • macOS version 15.3.1
  • Xcode 16.2
  • I've personally seen it probably once every 5 or 6 runs, but not sure about other team members

cluu-netflix avatar Mar 12 '25 14:03 cluu-netflix

We have not tried to disable fragment field merging as we use the merged fragment access all over our code so we wouldn't be able to compile without it.

cluu-netflix avatar Mar 12 '25 15:03 cluu-netflix

@cluu-netflix just for clarification are you seeing it across version of apollo-ios or in a specific one? I can revisit trying to create a reproduction case, do you think you would be able to create a sample reproduction case?

BobaFetters avatar Mar 12 '25 16:03 BobaFetters

What I've included here was what I thought would repro, but it doesn't, so I have no idea how to repro other than to create a gigantic schema with lots an lots of cases like that I have given as an example here.

jimisaacs avatar Apr 14 '25 15:04 jimisaacs

I'm closing this issue due to inactivity. If this is still unresolved, feel free to provide more information and we can re-open this, or create a new issue.

AnthonyMDev avatar Nov 13 '25 19:11 AnthonyMDev

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.

github-actions[bot] avatar Nov 13 '25 19:11 github-actions[bot]