Closed fvisticot closed 4 years ago
Not possible to do exactly that right now, but you could use the conditional mixin config to do something similar:
mixins:
# add the mixin {{name}} when the given fields are found in a model
- when:
fields:
- creationDate
name: FixDate
where FixDate
is something like
class FixDate {
String creationDate;
DateTime get created => DateTime.parse(creationDate).toLocal();
set created(DateTime date) => creationDate = date.toUtc().toIso8601String();
}
Not possible to do exactly that right now, but you could use the conditional mixin config to do something similar:
mixins: # add the mixin {{name}} when the given fields are found in a model - when: fields: - creationDate name: FixDate
where
FixDate
is something likeclass Entity { String creationDate; get creationDateFix => dateFromJson(creationDate); }
Sorry to disturb you again and big tx for your support
sorry, Entity
was a typo, should be FixDate
. So, you can add a ./base.dart
to parts
and place it there, next to your generates
target. So, if you're generating lib/serializers/graphql.dart
, this should work:
// in lib/serializers/base.dart
class FixDate {
String creationDate;
DateTime get created => DateTime.parse(creationDate).toLocal();
set created(DateTime date) => creationDate = date.toUtc().toIso8601String();
}
Config section of codegen.yml
:
config:
mixins:
# add the mixin {{name}} when the given fields are found in a model
- when:
fields:
- creationDate
name: FixDate
parts:
- "./base.dart"
- "./graphql.g.dart"
By example, the Schema I'm using is not managing date field properly and those date field are managed as String. I would like to overload type of some fields with configuration.
By Exemple: From Schema: creationDate String
I would like to transform to creationDate DateTime