NamePolicy
Documents the keyword escaping and identifier normalisation rules used by GraphNameAllocator when transforming GraphQL names into Kotlin identifiers.
Keyword Escaping Policy
Hard keywords (always escaped)
The full set of Kotlin hard keywords cannot be used as identifiers in any context. When a GraphQL name matches a hard keyword, the allocator appends the suffix Value to produce a readable renamed identifier:
private->privateValueobject->objectValuewhen->whenValueis->isValueclass->classValuefun->funValue
The original wire name is preserved separately in GeneratedName.wireName and used for @SerialName / @SerializedName annotations. This means the JSON key always matches the GraphQL schema, regardless of Kotlin keyword escaping.
Backticks are intentionally not used because they degrade readability in generated source code that consumers are expected to inspect directly.
Visibility modifiers (escaped as soft keywords)
The visibility modifiers private, protected, public, and internal are also escaped with the Value suffix. While these are technically soft keywords (valid as property names in data class member positions), they cause compilation ambiguity when used alongside actual visibility declarations. For safety, they are treated as reserved.
Digits at start
GraphQL names that start with a digit are prefixed with an underscore (e.g. 3dModel ->_3dModel).
Soft keywords (not escaped)
Other soft keywords (e.g. actual, data, inner, sealed, open) are not escaped because they are valid identifiers in most generated contexts (property names, parameter names, class names). If a consumer encounters a problem with a specific soft keyword in a specific context, file an issue and the policy will be extended.
Collision Resolution
When two distinct GraphQL names normalise to the same Kotlin identifier candidate, GraphNameAllocator delegates to KotlinPoet's NameAllocator which appends a deterministic underscore-based suffix (e.g. foo, foo_, foo__). This resolution is:
Scoped per allocator instance (per class, per operation, etc.)
Deterministic for the same input and same allocation order
Applied after keyword escaping
Case conventions
Property names: lowerCamelCase (the escaped name's first character is lowercased; the rest is preserved as-is from the GraphQL name).
Class names: PascalCase (the escaped name's first character is uppercased).
Enum constants: SCREAMING_SNAKE_CASE (the escaped name is uppercased in its entirety).
Since
1.0