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

impl create/update/delete mutations #125

Closed
wants to merge 4 commits into from
Closed

Conversation

floffel
Copy link

@floffel floffel commented Mar 26, 2023

Hi 👋
First of all: Thank you for your work, I already learned a lot! :)
I experimented with graphql and SeaQL and wanted some mutations... So I tried to implement it, following the style of the existing macros.

This PR introduces the new derive macro seaography::macros::Mutation for every model/entity and #[seaography_mutation(skip=true)] for every record to be skipped.

I would love to hear for you if this code could be of any use.

PR Info

New Features

  • create mutations
  • update mutations
  • delete mutations

Usage example:

examples/*/src/mutation_root.rs:

use async_graphql::MergedObject;

#[derive(MergedObject, Default)]
pub struct MutationRoot(crate::entities::actor::actorMutation, crate::entities::address::addressMutation);

examples/*/src/entities/actor.rs:

use sea_orm::entity::prelude::*;

#[derive(
    Clone,
    Debug,
    PartialEq,
    DeriveEntityModel,
    async_graphql::SimpleObject,
    seaography::macros::Filter,
    seaography::macros::Mutation
)]
#[sea_orm(table_name = "actor")]
#[graphql(complex)]
#[graphql(name = "Actor")]
pub struct Model {
    #[seaography_mutation(skip=true)]
    #[sea_orm(primary_key)]
    pub actor_id: i32,
    pub first_name: String,
    pub last_name: String,
    #[seaography_mutation(skip=true)]
    pub last_update: DateTime,
}

...

examples/*/src/entities/address.rs:

use sea_orm::entity::prelude::*;

#[derive(
    Clone,
    Debug,
    PartialEq,
    DeriveEntityModel,
    async_graphql::SimpleObject,
    seaography::macros::Filter,
    seaography::macros::Mutation
)]
#[sea_orm(table_name = "address")]
#[graphql(complex)]
#[graphql(name = "Address")]
pub struct Model {
    #[seaography_mutation(skip=true)]
    #[sea_orm(primary_key)]
    pub address_id: i32,
    pub address: String,
    pub address2: Option<String>,
    pub district: String,
    pub city_id: i16,
    pub postal_code: Option<String>,
    pub phone: String,
    #[seaography_mutation(skip=true)]
    pub last_update: DateTime,
}

examples/*/src/main.rs

    let mut schema = Schema::build(QueryRoot, MutationRoot::Default(), EmptySubscription)
        .data(database)
        .data(orm_dataloader);

@floffel floffel marked this pull request as draft March 26, 2023 19:01
@karatakis karatakis mentioned this pull request Apr 2, 2023
1 task
Copy link
Member

@billy1624 billy1624 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @floffel, looks promising!! I would like to see the mutation in action. Perhaps you can alter one of the example just like you descripted and add a mutation_tests.rs to the examples/*/test folder.

@billy1624 billy1624 requested a review from karatakis April 9, 2023 13:19
@billy1624
Copy link
Member

@karatakis any ideas?

@karatakis
Copy link
Collaborator

karatakis commented Apr 9, 2023

@billy1624 it needs to be ported to the functional API. After we finish the functional API I can continue the work. With the functional API we can skip the derive macro, so the task would be easier to implement.

Copy link
Member

@billy1624 billy1624 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @karatakis for the input!! I agree, we should come back to this after we finished implementing the functional API.

@karatakis karatakis mentioned this pull request Jul 28, 2023
2 tasks
@YiNNx YiNNx mentioned this pull request Nov 23, 2023
@floffel
Copy link
Author

floffel commented Aug 21, 2024

looks like my pr is not needed and not up to date as like karatakis said the mutations are now in the functional API...

@floffel floffel closed this Aug 21, 2024
@karatakis
Copy link
Collaborator

@floffel, thanks for the initial pull request. It was a great inspiration.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

Future: create one/many mutations
3 participants