Skip to content

Context based validation or modification #46

Open
@cwheel

Description

@cwheel

I've been playing around with wundergraph for a bit and I'm really liking it, but I'm a bit stuck on devising a method of operation authorization. I'd ideally like to be able to inspect instantiated models prior to inserting or updating and either allow the update, or, reject the update in consideration of the context.

I've been poking around in the source and it doesn't seem like there's any straight forward way to do this at the moment. I think(?) the easiest way of doing something like this might be to allow the implementation of a trait like:

impl<M, Ctx> WundergraphShouldInsert for MyInsertable<M, Ctx> {
    pub fn should_insert(model: &M, context: &Ctx) -> bool;
    // or
    pub fn should_insert(model: &M, context: &Ctx) -> Option<&M>;
}

In the case of inserting, it seems like this could probably be checked in the handle_insert call prior to actually asking Diesel to insert.

I'd also like something for reading/deleting, but I think the easiest cases to start with are probably insert/update. If this seems like something that you'd be interested in having Wundergraph support, I'd be happy to take a crack at implementing this. If I can already do this somehow and I'm missing it, I'd love to hear.

Thanks!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions