davidpdrsn / juniper-eager-loading

Library for avoiding N+1 query bugs with Juniper
68 stars 8 forks source link

DateTime in FileFields #61

Open DidierBoivin opened 4 years ago

DidierBoivin commented 4 years ago

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}**
davidpdrsn commented 4 years ago

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

DidierBoivin commented 4 years ago

Please do you have any example to use it

davidpdrsn commented 4 years ago

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

davidpdrsn commented 3 years ago

Did that example help?

DidierBoivin commented 3 years ago

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 notifications@github.com 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.