Question: How can we rely on specific fields in rules?
See original GitHub issueHello, first of all thanks for the great lib!
I have a a question. In docs there is a rule defined and used as:
const isOwner = rule()(async (parent, args, ctx, info) => {
return ctx.user.items.some(id => id === parent.id)
})
const permissions = shield({
/* ... */
User: {
secret: isOwner
},
})
The rule uses parent.id
which is ID of user to determine if the user is a owner. From what I’ve been able to understand by playing with this library, we can’t really rely on any field of parent
.
Let’s say the client queries something like:
query {
me {
id
secret
}
}
Where me
is a Query
which returns current user - then everything is correct. However, what if client queries a Query
:
query {
me {
# notice the missing ID
secret
}
}
then the parent.id
in isOwner
rule is undefined and we can’t correctly decide whether the user is owner or not.
How can the isOwner
rule be implemented correctly? Is there even a way to do that?
Thanks!
Issue Analytics
- State:
- Created 5 years ago
- Comments:10
Top Results From Across the Web
Question: How can we rely on specific fields in rules? #103
The rule uses parent.id which is ID of user to determine if the user is a owner. From what I've been able to...
Read more >Using Conditions and Rules - Zengine
Field Rules or Conditional Rules allow you to show or hide a field based on a response to a previous field. This is...
Read more >Guide to table relationships - Microsoft Support
You then provide Access with a way to bring the divided information back together — you do this by placing common fields in...
Read more >Use dependent form fields - HubSpot Knowledge Base
Learn how to use dependent form fields to ask further qualifying questions based on previous answers.
Read more >Is it possible to create firestore rules based on specific fields?
It's not possible to target specific fields like you are showing in security rules. You can only match whole documents with a match ......
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
Yes, thank you! For anyone else having the same problem, it should look like this:
Hey @nemcek 👋
That’s an interesting question, and indeed you are right! The current version doesn’t support
fragments
. Fragments are a way of telling graphql resolver which information your resolver requires to work correctly.The next version of shield should introduce this with the following syntax. Right now, we fully depend on
graphql-tools
PR andgrpahql-middleware
fragments support which should land in no time.I hope this covers your idea. Tell me if you have any thoughts on this as well! 🙂