generateLibrary function

LibraryDefinition generateLibrary(
  1. GraphQLSchema schema,
  2. String path,
  3. List<DocumentNode> gqlDocs,
  4. GeneratorOptions options,
  5. SchemaMap schemaMap
)

Generate queries definitions from a GraphQL schema and a list of queries, given Artemis options and schema mappings.

Implementation

LibraryDefinition generateLibrary(
  GraphQLSchema schema,
  String path,
  List<DocumentNode> gqlDocs,
  GeneratorOptions options,
  SchemaMap schemaMap,
) {
  final queriesDefinitions = gqlDocs
      .map((doc) => generateQuery(schema, path, doc, options, schemaMap))
      .toList();

  final allClassesNames = queriesDefinitions.fold<Iterable<String>>(
      [], (defs, def) => defs.followedBy(def.classes.map((c) => c.name)));

  mergeDuplicatesBy(allClassesNames, (a) => a, (a, b) {
    throw Exception('''Two classes were generated with the same name `$a`!
You may want to do either:
- Enable add_query_prefix on this schema_map
- Make queries_glob stricter, to gather less .graphql files on a single output
- Use alias on one of the places a `$a` field is requested''');
  });

  final basename = p.basenameWithoutExtension(path);
  final customImports = _extractCustomImports(schema.types, options);
  return LibraryDefinition(
    basename,
    queries: queriesDefinitions,
    customImports: customImports,
    customParserImport: options.customParserImport,
  );
}