Skip to content
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

Extension based inject_graphql #49

Open
billy1624 opened this issue Sep 6, 2022 · 0 comments
Open

Extension based inject_graphql #49

billy1624 opened this issue Sep 6, 2022 · 0 comments

Comments

@billy1624
Copy link
Member

I saw we're using some magic to inject graphql derives to Model, Relation and ActiveEnum. It's not future proof and depends heavily on the output of SeaORM codegen. Let say, the sea_orm attribute comes before derive, then the inject_graphql code will fail.

// `inject_graphql` expect this as the input
#[derive(Clone, Debug, PartialEq, DeriveEntityModel)]
#[sea_orm(table_name = "actor")]
pub struct Model {
    #[sea_orm(primary_key)]
    pub actor_id: u16,
    pub first_name: String,
    pub last_name: String,
    pub last_update: DateTimeUtc,
}

// How about this?
#[sea_orm(table_name = "actor")]
#[derive(Clone, Debug, PartialEq, DeriveEntityModel)]
pub struct Model {
    #[sea_orm(primary_key)]
    pub actor_id: u16,
    pub first_name: String,
    pub last_name: String,
    pub last_update: DateTimeUtc,
}

We can provide extension inside SeaORM codegen. For example, EntityWriterContext can store a Option<dyn ExtendModelStructWriter> where we can specify additional derives and attributes for the generated Model. The trait will take some context provided by the SeaORM codegen. Feel free to rename it or even take the context as &EntityWriterContext.

pub trait ExtendModelStructWriter {
    fn expended_model_extra_derives(entity: &Entity, with_serde: &WithSerde, date_time_crate: &DateTimeCrate) -> TokenStream;

    fn compact_model_extra_attributes(entity: &Entity, with_serde: &WithSerde, date_time_crate: &DateTimeCrate, schema_name: &Option<String>) -> TokenStream;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Triage
Development

No branches or pull requests

1 participant