generateEnum static method
Generates a complete enum definition from a GraphQL enum type definition.
This method processes a GraphQL enum type definition node and creates a corresponding Dart enum definition with all enum values, including the automatic UNKNOWN value for forward compatibility.
The generated enum includes:
- All enum values from the GraphQL schema
- Proper Dart naming conventions (converted from GraphQL naming)
- An UNKNOWN value for handling server-side schema evolution
- Support for deprecated enum values with appropriate annotations
node The GraphQL enum type definition node to process
context The generation context containing schema and configuration
Returns an EnumDefinition representing the complete Dart enum
Example:
final enumDef = EnumGenerator.generateEnum(enumNode, context);
// Generates: enum UserRole { ADMIN, USER, UNKNOWN }
Implementation
static EnumDefinition generateEnum(
EnumTypeDefinitionNode node,
Context context,
) {
final enumName = EnumName(name: node.name.value);
final nextContext = context.sameTypeWithNoPath(
alias: enumName,
ofUnion: Nullable<TypeDefinitionNode?>(null),
);
logFn(context, nextContext.align, '-> Enum');
logFn(
context,
nextContext.align,
'<- Generated enum ${enumName.namePrintable}.',
);
return EnumDefinition(
name: enumName,
values: generateEnumValues(node.values, context),
);
}