fromYaml static method

GraphQLGenConfig fromYaml(
  1. Map yaml, {
  2. required String packageName,
})

Implementation

static GraphQLGenConfig fromYaml(
  Map<dynamic, dynamic> yaml, {
  required String packageName,
}) {
  final schema = _map(yaml['schema']);
  final barrel = yaml['barrel'];

  return GraphQLGenConfig(
    packageName: packageName,
    schema: SchemaSource(
      file: schema['file'] as String? ?? 'schema.graphql',
      url: schema['url'] as String?,
      introspection: schema['introspection'] as bool? ?? false,
      headers: _stringMap(schema['headers']),
    ),
    output: yaml['output'] as String? ?? 'lib/api',
    layout: switch (yaml['layout']) {
      null || 'by_kind' => ModelLayout.byKind,
      'hotchocolate_dto' => ModelLayout.hotchocolateDto,
      final other => throw FormatException('Unknown layout "$other".'),
    },
    classPrefix: yaml['class_prefix'] as String? ?? 'Api',
    barrel: barrel == false ? null : barrel as String? ?? 'api.dart',
    modelsImport: yaml['models_import'] as String?,
    runtimeImport:
        yaml['runtime_import'] as String? ??
        'package:graphql_gen/graphql_gen.dart',
    scalars: _stringMap(yaml['scalars']),
    skipTypes: _stringList(yaml['skip_types']).map(RegExp.new).toList(),
    preserve: _stringList(yaml['preserve']),
    inputDefaultsRequired: yaml['input_defaults_required'] as bool? ?? false,
    classNames: _generatedFileMap(yaml['names']),
    fileNames: _generatedFileMap(yaml['files']),
  );
}