fieldsFromClass function

Iterable<Future<FieldInfo>> fieldsFromClass(
  1. InterfaceElement clazz,
  2. GeneratorCtx ctx, {
  3. bool isInput = false,
})

Implementation

Iterable<Future<FieldInfo>> fieldsFromClass(
  InterfaceElement clazz,
  GeneratorCtx ctx, {
  bool isInput = false,
}) {
  if (clazz.name == 'Object') {
    return [];
  }
  final generics = Map.fromEntries(
    clazz.typeParameters.map((e) => MapEntry(e.name, e)),
  );

  final config = getClassConfig(ctx, clazz);

  bool _whereName(Element e) {
    final omit = const TypeChecker.fromRuntime(GraphQLField)
        .firstAnnotationOf(e)
        ?.getField('omit')
        ?.toBoolValue();
    final name = e.name;
    if (name == null) return false;
    return omit == false ||
        (!ctx.config.omitFieldsNamed.contains(name) &&
            !name.startsWith('__') &&
            (!name.startsWith('_') || !ctx.config.omitPrivateFields));
  }

  return [
    if (!isInput)
      ...clazz.methods
          .where((method) => _whereName(method) && !method.isStatic)
          .map((m) => fieldFromElement(config, m, m.returnType, ctx, generics)),
    ...clazz.fields
        .where(_whereName)
        .map((m) => fieldFromElement(config, m, m.type, ctx, generics)),
    if (clazz.supertype != null)
      ...fieldsFromClass(clazz.supertype!.element, ctx, isInput: isInput),
    ...clazz.interfaces
        .expand((m) => fieldsFromClass(m.element, ctx, isInput: isInput)),
  ];
}