generateLibrary function

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

Generates a complete library definition from GraphQL documents and schema.

This is the main entry point for generating Dart code from GraphQL documents. It coordinates the entire generation process by:

  1. Creating necessary services (SchemaService, FileService, GenerationService)
  2. Delegating the generation work to the GenerationService
  3. Returning a complete LibraryDefinition with all generated code

Parameters:

  • path - The file path for the generated library (used for naming)
  • gqlDocs - List of GraphQL documents containing queries, mutations, subscriptions
  • options - Generator configuration options (naming schemes, features, etc.)
  • schemaMap - Schema mapping configuration for type resolution
  • fragmentsCommon - Common fragments shared across documents
  • schema - The GraphQL schema document

Returns: A LibraryDefinition containing all generated classes, queries, and metadata

Throws:

Example:

final library = generateLibrary(
  'lib/graphql/queries.dart',
  [queryDocument, mutationDocument],
  GeneratorOptions(),
  SchemaMap(),
  [],
  schemaDocument,
);

Implementation

LibraryDefinition generateLibrary(
  String path,
  List<DocumentNode> gqlDocs,
  GeneratorOptions options,
  SchemaMap schemaMap,
  List<FragmentDefinitionNode> fragmentsCommon,
  DocumentNode schema,
) {
  // Create services with dependency injection
  final schemaService = SchemaService(schema);
  const fileService = FileService.instance;
  final generationService = GenerationService(
    schemaService: schemaService,
    fileService: fileService,
  );

  // Use GenerationService to generate the library
  return generationService.generateLibrary(
    path,
    gqlDocs,
    options,
    schemaMap,
    fragmentsCommon,
  );
}