Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 25 additions & 5 deletions codegen/gql_code_builder/lib/src/tristate_optionals.dart
Original file line number Diff line number Diff line change
Expand Up @@ -186,11 +186,8 @@ String _generateFieldDeserializers(
final typeDefNode =
getTypeDefinitionNode(schemaSource.document, originalSymbolName);

//TODO this feels flaky, find a better way
final isBuilder = type.url != null &&
!isWrappedValue &&
(typeDefNode is! ScalarTypeDefinitionNode &&
typeDefNode is! EnumTypeDefinitionNode);
// Check if this is a built type that needs .replace() method
final isBuilder = !isWrappedValue && _isBuiltType(type, typeDefNode);

const fieldNameVariableName = "_\$fieldValue";

Expand Down Expand Up @@ -295,3 +292,26 @@ bool _isValue(Reference ref) {

return ref.symbol == valueTypeRef.symbol && ref.url == valueTypeRef.url;
}

bool _isBuiltType(TypeReference type, TypeDefinitionNode? typeDefNode) {
// Built collection types (BuiltList, BuiltMap, etc.)
final bool isFromBuiltCollectionPackage =
type.url?.contains("built_collection") ?? false;
if (isFromBuiltCollectionPackage) {
return true;
}

// Built value types (generated classes that implement Built)
if (typeDefNode != null &&
(typeDefNode is InputObjectTypeDefinitionNode ||
typeDefNode is ScalarTypeDefinitionNode)) {
return true;
}

// Types with Builder suffix pattern
if (type.symbol.endsWith("Builder")) {
return true;
}

return false;
}