-
-
Notifications
You must be signed in to change notification settings - Fork 54
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fromJson with DateTime (and custom types) expects String #348
Comments
So, if I understand you correctly, you want custom parsing of |
Not correctly. The idea is to check runtime type before doing any kind of parse (in the example DateTime.parse). |
But `DateTime` is not a valid json type, so this check does not make sense
to me. Are you able to explain why providing your parsing logic through the
function as mentioned above does not work in your example?
…On Sun, 14 Apr 2024 at 21:01, Ciro Carandente (Coda) < ***@***.***> wrote:
So, if I understand you correctly, you want custom parsing of DateTime.
If this is the case, you can follow the pattern you are using for timetz
and provide the fromJsonFunctionName and toJsonFunctionName. See #349
<#349> for an example.
Not correctly. The idea is to check runtime type before doing any kind of
parse (in the example DateTime.parse).
—
Reply to this email directly, view it on GitHub
<#348 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AA2UFS2OG34VPMKP3IRQVCLY5LOCHAVCNFSM6AAAAABGGJHM7OVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDANJUGE3DSNRXHA>
.
You are receiving this because you were mentioned.Message ID:
***@***.***>
|
Well, why should we limitate final input = InputTripsSetInput.fromJson({
'arrivalDate': DateTime.now();
}); Unluckly my specific case requires me to use |
Just to give you some background about my actual code, I have a library that tells me each time a cell changes. This is the code: Future<void> _onChanged(PlutoGridOnChangedEvent event) async {
final data = <String, dynamic>{};
final id = event.row.cells['id']!.value;
if (event.value is Map) {
final m = event.value as Map;
for (final key in m.keys) {
data[key] = m[key];
}
} else {
data[event.column.field] = event.value;
}
final request = await context.client.mutateUpdateTrip(
OptionsMutationUpdateTrip(
variables: VariablesMutationUpdateTrip(
id: id,
$set: InputTripsSetInput.fromJson(data),
),
),
);
if (request.hasException && mounted) {
context.showErrorAlert(
'pages.tripList.errors.genericError'.tr(
namedArgs: {
'fieldName': event.column.field,
},
),
);
}
}
Doing so I can just create |
The |
Well, it’s not about being 'bothered,' but I understand your point and I disagree. I used the ferry library, and the code provided worked fine, accommodating different use cases like mine without the need for extra code (it’s literally just a type check, lol). Anyway, I've already implemented the custom scalar parsing, but I thought it could be a positive change for the library, that’s all. |
I have this schema:
where
date
andtimetz
are scalars defined like this in thebuild.yaml
:Now the input model
fromJson
method generated is the following:The problem here is that it's trying to use
DateTime.parse
instead of usingl$arrivalDate as DateTime
. Is this an error or an expected output? Doing so, we have two limitations:DateTime.parse
preventing us from using a different parserDateTime -> String -> DateTime
I was thinking about two workarounds:
String
runDateTime.parse
otherwise if runtime type isDateTime
assign it.My proposal is to just use the first "workaround" which would allow the method to handle both
String
andDateTime
types gracefully, thus avoiding unnecessary parsing and potential errors or performance issues with unnecessary string-to-date conversions. And the same could be implemented for other types like forarrivalHour
in my example below.The text was updated successfully, but these errors were encountered: