juniper-eager-loading
juniper-eager-loading copied to clipboard
DateTime in FileFields
Hi,
How can I use DateTime in this example
The compiler says expected struct file::DateTime
, found struct chrono::DateTime
file is the name of my module
Thanks
agenda : crate::models::Agenda,
// these are the defaults. `#[has_one(default)]` would also work here.
#[has_one(
foreign_key_field = prestation_id,
root_model_field = prestation,
graphql_field = prestation
)]
prestation: HasOne<Prestation>,
}
iimpl AgendaFields for Agenda {
fn field_id(&self, _executor: &Executor<'_, Context>) -> FieldResult<&i32> {
Ok(&self.agenda.id)
}
fn field_prestation(
&self,
_executor: &Executor<'_, Context>,
_trail: &QueryTrail<'_, Prestation, Walked>,
) -> FieldResult<&Prestation> {
self.prestation.try_unwrap().map_err(From::from)
}
fn field_agenda_number(&self, _: &juniper::Executor<Context>) -> std::result::Result<&i32, juniper::FieldError> {
Ok(&self.agenda.agenda_number) }
fn field_contact_person(&self, _: &juniper::Executor<Context>) -> std::result::Result<&std::option::Option<std::string::String>, juniper::FieldError> {
Ok(&self.agenda.contact_person) }
**### fn field_date_agenda_creation(&self, _: &juniper::Executor<Context>) -> std::result::Result<&std::option::Option<DateTime>, juniper::FieldError> {
let resultat = &Some(self.agenda.date_agenda_creation);
Ok(resultat}**
Juniper-from-schema always uses chrono when generating code for dates. So if you want to use some other date type you need to accept the chrono value in your 'field_*' methods and manually convert it.
I recommend you give the docs a read since there is more details and examples there https://docs.rs/juniper-from-schema/0.5.2/juniper_from_schema/#special-case-scalars
Please do you have any example to use it
This one shows a field that returns Date
and DateTimeUtc
https://github.com/davidpdrsn/juniper-from-schema/blob/master/juniper-from-schema/tests/compile_pass/dates_and_times.rs
Did that example help?
Hi, The problem I have with Date is my appolo client in my React font end is unable to render a Date correctly so I convert the string I receive from React appolo client in juniper to a DateTime struct The graphclient web interface is working fine with DateTime and juniper but not the Appolo client in React, I am currently investigate
Best Regards
Didier Boivin
Le 28 oct. 2020 à 18:15, David Pedersen [email protected] a écrit :
Juniper-from-schema always uses chrono when generating code for dates. So if you want to use some other date type you need to accept the chrono value in your 'field_*' methods and manually convert it.
I recommend you give the docs a read since there is more details and examples there https://docs.rs/juniper-from-schema/0.5.2/juniper_from_schema/#special-case-scalars https://docs.rs/juniper-from-schema/0.5.2/juniper_from_schema/#special-case-scalars — You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/davidpdrsn/juniper-eager-loading/issues/61#issuecomment-718082710, or unsubscribe https://github.com/notifications/unsubscribe-auth/ALOEWJKNUTAAEUI7MJ2A4FDSNBGSTANCNFSM4TCFONCA.