Rules with parameters
See original GitHub issueIs there a way to have a rule with some input arguments?
I am trying to make a rule like this:
const hasRole = (roleName: string) =>
rule(`userHasRole-${roleName}`)(
async (parent, args, ctx, info) => {
return (ctx.user && ctx.user.role === roleName);
}
);
And then use it in this way:
Mutation: {
createUser: and(user.hasRole("admin"), input.createUser),
},
And this gives me a run-time error:
Error: There seem to be multiple definitions of these rules: userHasRole-admin
I understand that this is exactly what is explained in the documentation. However my question remains, is there a way to have such rules with graphql-shield
? I want to use rules for different claims that may be issued to a user. The total number of claims may be quite big and I don’t really want to define a separate function for every claim/role that may exist.
Issue Analytics
- State:
- Created 4 years ago
- Comments:9
Top Results From Across the Web
Rules for defining parameters and attributes - IBM
Parameters are required and positional. Each parameter list has a fixed number of parameters. Each parameter is defined as an integer or a...
Read more >List of Rule Parameters
List of Rule Parameters ; Strict policy calculation. Defines the conditions under which a measurement's status can improve. If the parameter value is...
Read more >Rule with parameters—ArcGIS CityEngine Resources
In this topic. Rules can be parameterized; in other words, a signature with parameters can be defined, and the matching signature is chosen...
Read more >Using Parameters as a Business Rule - Oracle Help Center
These execution variables are passed as parameters. The check box for execution variables with a Rule scope is clear by default, because these...
Read more >What's the difference between a rule and a parameter?
Generally a Parameter is a part of a rule. For every rule you can define individually Parameters. For. With the Parameters you can...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Hey 👋 ,
That’s a fascinating question. Could you try creating role-specific rules before assigning them to the rule tree? Something like that:
What the error is saying is that you are trying to use two different rules with the same name (because you create multiple instances). Let me know if that worked; otherwise, we’ll try something new 😄
@peterrogov happy to hear that. Thank you for a great thread!
I’ll close the issue as it seems to be resolved but feel free to reopen in case you feel there’s more to it.