classInfoFromConstructor function

Future<UnionVarianInfo> classInfoFromConstructor(
  1. GeneratorCtx ctx,
  2. InterfaceElement clazz,
  3. ConstructorElement con, {
  4. required bool isUnion,
  5. required Iterable<Future<FieldInfo>> unionClassFields,
  6. GraphQLInput? inputConfig,
  7. GraphQLObject? classConfig,
})

Implementation

Future<UnionVarianInfo> classInfoFromConstructor(
  GeneratorCtx ctx,
  InterfaceElement clazz,
  ConstructorElement con, {
  required bool isUnion,
  required Iterable<Future<FieldInfo>> unionClassFields,
  GraphQLInput? inputConfig,
  GraphQLObject? classConfig,
}) async {
  final className = ReCase(clazz.name).pascalCase;
  final redirectedName = con.redirectedConstructor?.returnType
          .getDisplayString(withNullability: false) ??
      con.name;

  final generics = Map.fromEntries(
    clazz.typeParameters.map((e) => MapEntry(e.name, e)),
  );

  return UnionVarianInfo(
    isInterface: isInterface(clazz),
    typeParams: clazz.typeParameters,
    hasFrezzed: true,
    isUnion: isUnion,
    interfaces: getGraphQLInterfaces(ctx, clazz),
    hasFromJson: hasFromJson(clazz),
    classConfig: classConfig,
    typeName: isUnion ? redirectedName : className,
    constructorName: isUnion ? con.name : redirectedName,
    unionName: className,
    inputConfig: inputConfig,
    description: getDescription(con, con.documentationComment),
    deprecationReason: getDeprecationReason(con),
    fields: await Future.wait(
      con.parameters
          .map((p) => fieldFromParam(
                ctx,
                classConfig,
                p,
                isInput: inputConfig != null,
                generics: generics,
              ))
          .followedBy(unionClassFields),
    ),
    attachments: getAttachments(clazz),
  );
}