Send custom variable to the rules
See original GitHub issueI couldn’t find a way to send variables to the rule via shield. I’d like to do something similar to this and be able to send multiple variables to the rule(), is it doable? I’ve seen it’s used for cache and fragment, but is there a way?
const rules = shield({
Mutation: {
addPage: hasPermission("create", "page"),
addSpecialPage: hasPermission("create", "special_page"),
},
});
const hasPermission = rule(action, resource)(async (parent, args, ctx, info) => {
return true;
});
Issue Analytics
- State:
- Created 5 years ago
- Comments:5
Top Results From Across the Web
Send custom variable to the rules · Issue #170
I couldn't find a way to send variables to the rule via shield. I'd like to do something similar to this and be...
Read more >Adding a Rule-Based Paths for Custom Variables
In the Rule-based path section, click the Add rule button. Provide a name for the rule in the Rule name text field. Click...
Read more >How to add and change variables - Help Center
1. Open the branching menu and click + Add rule by the question you want to edit.
Read more >Using CSS custom properties (variables) - MDN Web Docs
Custom properties (sometimes referred to as CSS variables or cascading variables) are entities defined by CSS authors that contain specific ...
Read more >How to be able to pass variable to rules in gitlab ci pipeline?
stages: - one - two first: stage: one script: # create dotenv file with variables to pass - echo "VAR_NAME=foo" >> "myvariables.env" ...
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 @gmahe 👋,
That’s an interesting question! I believe you could solve it by making a rule “constructor” or maybe more of a wrapper.
Pay attention to the
createHashableName
function. I have used a function to define the name of a rule, but you could also providestring
directly. This is especially important forcaching
functionality sincegraphql-shield
relies on naming conventions of your application. In that sense, if you are to give the same name to two different rules, it will warn you. Long story short, if anything might go wrong, you’ll be warned.Let me know if you need any help with the implementation! 🙂
PS.:
shield
generate rules like this;${name}-${suffix}
where the name can be predefined value - like in our case, or a random number assigned to a particular rule. Don’t make a mistake though; rule’s name is generated during rule construction. In that sense, if you reuse the same rule multiple times in your permission tree, it has the same identifier, or, based on your functionality, it should appropriately differ.suffix
, on the other hand, is defined based on thecache
option you choose.no_cache
yet again generates a random identifier,contextual
has nosuffix
since it won’t differ during execution, andstrict
hashes thesuffix
based onparent
andargs
of the resolver.A simple cheat sheet;
name
-> construction (shield({})
,new GraphQLServer
)suffix
-> execution ({ query }
,args
)@maticzav My bad I’ve got confused with the rule’s name in case if
action
is an arrayrule-${action}${resource}