Closed ValentinVignal closed 5 months ago
hm, there's the add_typenames
option for code generation. But I would not recommend deactivating this globally, especially if you use inline fragments with type conditions.
Yeah, I don't think that is a good idea to deactivate it globally. In the end, I created a SerializerPlugin
to remove the __typename
from the json:
import 'package:built_value/serializer.dart';
/// A plugin that removes the `__typename` field from the serialized data.
class RemoveTypenamePlugin extends SerializerPlugin {
@override
Object? afterDeserialize(Object? object, FullType specifiedType) {
return object;
}
@override
Object? afterSerialize(Object? object, FullType specifiedType) {
if (object is Map && object.containsKey('__typename')) {
return Map<String, dynamic>.from(object as Map<String, dynamic>)..remove('__typename');
} else {
return object;
}
}
@override
Object? beforeDeserialize(Object? object, FullType specifiedType) {
return object;
}
@override
Object? beforeSerialize(Object? object, FullType specifiedType) {
return object;
}
}
that I can add to my serializers when needed
It is a follow-up of https://github.com/gql-dart/ferry/issues/527
I have a schema
and created a fragment
The issue I have now is that the
G__typename
field is included as__typename
in the json generated from thetoJson()
. Is there a way to not include__typename
in some scenarios?