Baumgaer / boilerplate

2 stars 0 forks source link

implement query and mutation actions #37

Open Baumgaer opened 2 years ago

Baumgaer commented 2 years ago

Because we want to use DDD while development we should implement a mechanism which forces the developer to definitely use this architecture. To enforce this we have to implement two new decorators:

Each of this decorators should enforce to define access rights, an atomic action name (e.g. lock, unlock, getBooks, setBook and so on). The name could be determined by the transformer loke the transformer does it already for the fields. It also should take care about the return type.

To enforce type savety for the parameters given to the function decorated with this decorators. we should use another decorator:

Baumgaer commented 2 years ago

This hase to take care about #15

Baumgaer commented 2 years ago

We should care about type-graphql to be able to switch fast to it in case this idea her isn't that good.

Baumgaer commented 2 years ago

After testing a little bit I came up with the following solution:

@Mutation({ name: "changeName", accessRight: () => true })
public changeName(@Arg() name: string) {
    this.name = name;
    return this.save();
}

@Query({ name: "queryDeletedNames", accessRight: () => /*some other magic here*/ true })
public queryDeletedNames(@Arg() conditionalDate: Date) {
    return (this.constructor as typeof Example).find({ select: ["name"], where: { deletedAt: conditionalDate } });
}

As we can see the name of the action corresponds to the methods name most times. So the name should be optional in case it's really different from the methods name. We can pass the name of the action during transformation.

Every action should perform its own procedure locally and NOT call a server. this will be done in the model class by getting the arguments decorated with the @Arg() and will build the corresponding query or mutation.

Baumgaer commented 2 years ago

The decorators are already implemented but we have to:

to be able to use it completely.