visitSelectionSetNode method

  1. @override
void visitSelectionSetNode(
  1. SelectionSetNode node
)

Visit SelectionSetNode.

Implementation

@override
void visitSelectionSetNode(SelectionSetNode node) {
  final nextContext = context.withAlias();

  logFn(context, nextContext.align, '-> Class');
  logFn(context, nextContext.align,
      '┌ ${nextContext.path}[${nextContext.currentType!.name.value}][${nextContext.currentClassName} ${nextContext.currentFieldName}] (${nextContext.alias ?? ''})');
  super.visitSelectionSetNode(node);

  final possibleTypes = <String, Name>{};

  if (nextContext.currentType is UnionTypeDefinitionNode ||
      nextContext.currentType is InterfaceTypeDefinitionNode) {
    // Filter by requested types
    final keys = node.selections
        .whereType<InlineFragmentNode>()
        .map((n) => n.typeCondition?.on.name.value)
        .whereType<String>();

    final values = keys.map((t) => ClassName.fromPath(
        path:
            nextContext.withAlias(alias: ClassName(name: t)).fullPathName()));

    possibleTypes.addAll(Map.fromIterables(keys, values));
  }

  final partOfUnion = nextContext.ofUnion != null;
  if (partOfUnion) {}

  final name = ClassName.fromPath(path: nextContext.fullPathName());
  logFn(context, nextContext.align,
      '└ ${nextContext.path}[${nextContext.currentType!.name.value}][${nextContext.currentClassName} ${nextContext.currentFieldName}] (${nextContext.alias ?? ''})');
  logFn(context, nextContext.align,
      '<- Generated class ${name.namePrintable}.');

  nextContext.generatedClasses.add(ClassDefinition(
    name: name,
    properties: _classProperties,
    mixins: _mixins,
    extension: partOfUnion
        ? ClassName.fromPath(path: nextContext.rollbackPath().fullPathName())
        : null,
    factoryPossibilities: possibleTypes,
  ));
}