Fixes issue with multiple nested fragments on interface and union
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 🥳 .
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 ...
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.
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