@@ -52,22 +52,20 @@ class GeneratorVisitor extends RecursiveVisitor {
5252 possibleTypes.addAll (Map .fromIterables (keys, values));
5353 }
5454
55- final partOfUnion = nextContext.ofUnion != null ;
56- if (partOfUnion) {}
57-
5855 final name = ClassName .fromPath (path: nextContext.fullPathName ());
5956 logFn (context, nextContext.align,
6057 '└ ${nextContext .path }[${nextContext .currentType !.name .value }][${nextContext .currentClassName } ${nextContext .currentFieldName }] (${nextContext .alias ?? '' })' );
6158 logFn (context, nextContext.align,
6259 '<- Generated class ${name .namePrintable }.' );
63-
60+ final ofUnion = context.ofUnion;
61+ if (ofUnion is FragmentName ) {
62+ _mixins.add (ofUnion);
63+ }
6464 nextContext.generatedClasses.add (ClassDefinition (
6565 name: name,
6666 properties: _classProperties,
6767 mixins: _mixins,
68- extension : partOfUnion
69- ? ClassName .fromPath (path: nextContext.rollbackPath ().fullPathName ())
70- : null ,
68+ extension : ofUnion is ClassName ? ofUnion : null ,
7169 factoryPossibilities: possibleTypes,
7270 ));
7371 }
@@ -94,15 +92,16 @@ class GeneratorVisitor extends RecursiveVisitor {
9492 void visitInlineFragmentNode (InlineFragmentNode node) {
9593 logFn (context, context.align + 1 ,
9694 '${context .path }: ... on ${node .typeCondition !.on .name .value }' );
95+ final ofUnion = context.ofUnion ??
96+ ClassName .fromPath (path: context.rollbackPath ().fullPathName ());
9797 final nextType = gql.getTypeByName (context.schema, node.typeCondition! .on );
98-
9998 if (nextType.name.value == context.currentType! .name.value) {
10099 final visitor = GeneratorVisitor (
101100 context: context.nextTypeWithSamePath (
102101 nextType: nextType,
103102 nextClassName: null ,
104103 nextFieldName: null ,
105- ofUnion: Nullable <TypeDefinitionNode ?>(context.currentType ),
104+ ofUnion: Nullable <Name ?>(ofUnion ),
106105 inputsClasses: [],
107106 fragments: [],
108107 ),
@@ -114,7 +113,7 @@ class GeneratorVisitor extends RecursiveVisitor {
114113 nextType: nextType,
115114 nextClassName: ClassName (name: nextType.name.value),
116115 nextFieldName: ClassPropertyName (name: nextType.name.value),
117- ofUnion: Nullable <TypeDefinitionNode ?>(context.currentType ),
116+ ofUnion: Nullable <Name ?>(ofUnion ),
118117 inputsClasses: [],
119118 fragments: [],
120119 ),
@@ -149,7 +148,7 @@ class GeneratorVisitor extends RecursiveVisitor {
149148 nextType: leafType,
150149 nextClassName: ClassName (name: leafType.name.value),
151150 nextFieldName: ClassName (name: node.variable.name.value),
152- ofUnion: Nullable <TypeDefinitionNode ?>(null ),
151+ ofUnion: Nullable <Name ?>(null ),
153152 )
154153 .fullPathName ();
155154
@@ -234,15 +233,15 @@ class GeneratorVisitor extends RecursiveVisitor {
234233 path: context
235234 .sameTypeWithNoPath (
236235 alias: FragmentName (name: node.name.value),
237- ofUnion: Nullable <TypeDefinitionNode ?>(null ),
236+ ofUnion: Nullable <Name ?>(null ),
238237 )
239238 .fullPathName ());
240239
241240 final visitor = GeneratorVisitor (
242241 context: context.sameTypeWithNextPath (
243242 alias: fragmentName,
244243 generatedClasses: [],
245- ofUnion: Nullable <TypeDefinitionNode ?>(null ),
244+ ofUnion: Nullable <Name ?>(null ),
246245 log: false ,
247246 ),
248247 );
@@ -260,7 +259,7 @@ class GeneratorVisitor extends RecursiveVisitor {
260259 final partName = FragmentName (name: node.name.value);
261260 final nextContext = context.sameTypeWithNoPath (
262261 alias: partName,
263- ofUnion: Nullable <TypeDefinitionNode ?>(null ),
262+ ofUnion: Nullable <Name ?>(null ),
264263 );
265264
266265 logFn (context, nextContext.align, '-> Fragment' );
@@ -270,6 +269,8 @@ class GeneratorVisitor extends RecursiveVisitor {
270269
271270 final nextType =
272271 gql.getTypeByName (nextContext.schema, node.typeCondition.on );
272+ final fragmentName =
273+ FragmentName .fromPath (path: nextContext.fullPathName ());
273274
274275 final visitorContext = Context (
275276 schema: context.schema,
@@ -285,6 +286,7 @@ class GeneratorVisitor extends RecursiveVisitor {
285286 fragments: [],
286287 usedEnums: nextContext.usedEnums,
287288 usedInputObjects: nextContext.usedInputObjects,
289+ ofUnion: fragmentName,
288290 );
289291
290292 final visitor = GeneratorVisitor (context: visitorContext);
@@ -298,8 +300,6 @@ class GeneratorVisitor extends RecursiveVisitor {
298300 .expand ((a) => a)
299301 .mergeDuplicatesBy ((a) => a.name, (a, b) => a);
300302
301- final fragmentName =
302- FragmentName .fromPath (path: nextContext.fullPathName ());
303303 logFn (context, nextContext.align,
304304 '└ ${nextContext .path }[${node .name .value }]' );
305305 logFn (context, nextContext.align,
0 commit comments