generateObjectFromFields function

Future<Library> generateObjectFromFields(
  1. GeneratorCtx ctx,
  2. InterfaceElement clazz
)

Implementation

Future<Library> generateObjectFromFields(
  GeneratorCtx ctx,
  InterfaceElement clazz,
) async {
  final className = clazz.name;
  final redirectedName =
      clazz.constructors.firstWhere(isFreezedVariantConstructor).name;
  final classInfo = UnionVarianInfo(
    isInterface: isInterface(clazz),
    typeParams: clazz.typeParameters,
    hasFrezzed: false,
    isUnion: false,
    inputConfig: null,
    hasFromJson: hasFromJson(clazz),
    classConfig: getClassConfig(ctx, clazz),
    interfaces: getGraphQLInterfaces(ctx, clazz),
    typeName: className,
    constructorName: redirectedName.isEmpty ? className : redirectedName,
    unionName: className,
    description: getDescription(clazz, clazz.documentationComment),
    deprecationReason: getDeprecationReason(clazz),
    fields: await Future.wait(fieldsFromClass(clazz, ctx)),
    attachments: getAttachments(clazz),
  );
  return Library((l) {
    // l.directives.addAll(
    //   ctx.config.customTypes.map((e) => Directive.import(e.import)),
    // );

    l.body.add(classInfo.serializer());
    l.body.add(Code(classInfo.typeDefinitionCode()));
  });
}