gql icon indicating copy to clipboard operation
gql copied to clipboard

Fixes issue with multiple nested fragments on interface and union

Open letsar opened this issue 5 months ago • 3 comments

This PR aims to fix https://github.com/gql-dart/ferry/issues/610. I don't fully understand the code, so I'm not sure why I needed to use superclassSelections instead of context.hierarchy in inline_fragment_classes.dart, but it seems to work. I've tested it in our codebase and so far I don't see any regression and we can now use the kind of fragments discussed in the issue 🥳 .

letsar avatar Oct 30 '25 09:10 letsar

Thanks so much for this!

I am currently trying to understand why this would work ;)

Oh...

void addInterface(String name) {
    final parts = name.split("__");           // Split on "__"
    final base = parts[0];                    // e.g., "GHeroData_hero"
    hierarchy.putIfAbsent(base, () => {});    // Create entry for base
    if (parts.length > 1) {                   // If specialized version
      hierarchy[base]!.add(name);             // Add to base's set
    }
  }

I think the culprit is just the naive split on the first __, which breaks down in nested scenarios ...

knaeckeKami avatar Nov 01 '25 12:11 knaeckeKami

Hello, I don't have the time right now to explain a little further, but this fix introduced a regression when we use a named Fragment on a specific union type, which select a field which is an interface. I didn't have a simple repro case for now, but I wanted to warn you about this. I didn't look at the addInterface method, but yes maybe, the solution is there after all.

letsar avatar Nov 17 '25 14:11 letsar

Thanks! I already stumbled upon this or something similar when trying to write more comprehensive regression tests for this - which is why I did not merge this yet. did not have time to look into it further yet

knaeckeKami avatar Nov 17 '25 14:11 knaeckeKami