Async-graphql: Rework guard parsing

Created on 2 Oct 2020  路  5Comments  路  Source: async-graphql/async-graphql

Hello,

I use the repository for a project in my company and I want to help a bit to contribute to the amazing work you guys doing.

I figured out that guard only support (implicitly) and operator which accept x numbers of rules and the implementation is very specific to this operator.

If we take graphql-shield (a huge guard module for graphql api in typescript) as a example they implement some others operators :

  • and
  • or
  • not
  • chain
  • race

I would like to rework the actual implementation to make a recursive parsing on operators and so be able to parse things like :

#[graphql(guard(
     and(
         or(
             RoleGuard(role = "Role::Admin"),
             RoleGuard(role = "Role::Guest")
         ),
         UserGuard(username = r#""test""#)
     )
))]

You can find explanations about each operators here.

It's my first work on this project and on macros in general so I started look deep into generate_guards() and I understand how the function work. I start working on a first version of the implementation and I will submit a PR in draft soon.

Most helpful comment

I don't know darling, I started doing the parsing the same functions that you used. Maybe I can make a v2 with darling after I practice with macros

All 5 comments

Great, look forward to it! Post guard I think you can delete it, it's not too useful. Attributes parsing for procedural macros is recommended use darling crate, which is very handy. 馃槂

I don't know darling, I started doing the parsing the same functions that you used. Maybe I can make a v2 with darling after I practice with macros

I don't think implement the not operator seems relevant because we can't return the error defined in the check function of the user.

What do you think about it @sunli829 ?

I don't think implement the not operator seems relevant because we can't return the error defined in the check function of the user.

What do you think about it @sunli829 ?

you're right. 馃榿

Was this page helpful?
0 / 5 - 0 ratings