Skip to content

Commit bfe7a2b

Browse files
committed
fix(gql_code_builder): isBuilder detection
Signed-off-by: Dan Printzell <dan@dagg.ai>
1 parent b371b1a commit bfe7a2b

File tree

1 file changed

+25
-5
lines changed

1 file changed

+25
-5
lines changed

codegen/gql_code_builder/lib/src/tristate_optionals.dart

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -186,11 +186,8 @@ String _generateFieldDeserializers(
186186
final typeDefNode =
187187
getTypeDefinitionNode(schemaSource.document, originalSymbolName);
188188

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

195192
const fieldNameVariableName = "_\$fieldValue";
196193

@@ -295,3 +292,26 @@ bool _isValue(Reference ref) {
295292

296293
return ref.symbol == valueTypeRef.symbol && ref.url == valueTypeRef.url;
297294
}
295+
296+
bool _isBuiltType(TypeReference type, TypeDefinitionNode? typeDefNode) {
297+
// Built collection types (BuiltList, BuiltMap, etc.)
298+
final bool isFromBuiltCollectionPackage =
299+
type.url?.contains("built_collection") ?? false;
300+
if (isFromBuiltCollectionPackage) {
301+
return true;
302+
}
303+
304+
// Built value types (generated classes that implement Built)
305+
if (typeDefNode != null &&
306+
(typeDefNode is InputObjectTypeDefinitionNode ||
307+
typeDefNode is ScalarTypeDefinitionNode)) {
308+
return true;
309+
}
310+
311+
// Types with Builder suffix pattern
312+
if (type.symbol.endsWith("Builder")) {
313+
return true;
314+
}
315+
316+
return false;
317+
}

0 commit comments

Comments
 (0)