I'm trying to make a permission variable that is using a many-to-many relationship. Something like this: `'{"company-ids":"companies.companyId"}'` When the user has many companies, it looks like this in the token, and I can use the `_in` operator in the permission rule to check `"x-hasura-company-ids": "{\"33333333-3333-3333-3333-333333333333\",\"33333333-3333-3333-3333-333333333333\"}"` However, if the user only has one company it looks like this, and the check breaks `"x-hasura-company-ids": "33333333-3333-3333-3333-333333333333"` And I get this error: `malformed array literal: \"33332a37-f01c-4195-9360-268136725b06\"` I understand that moving the single element out of an array is probably useful more often than not π but is there a smart way to work around this?
Last active 4 months ago
10 replies
5 views
- MO
I'm trying to make a permission variable that is using a many-to-many relationship.
Something like this:
'{"company-ids":"companies.companyId"}'
When the user has many companies, it looks like this in the token, and I can use the
_in
operator in the permission rule to check
"x-hasura-company-ids": "{\"33333333-3333-3333-3333-333333333333\",\"33333333-3333-3333-3333-333333333333\"}"
However, if the user only has one company it looks like this, and the check breaks
"x-hasura-company-ids": "33333333-3333-3333-3333-333333333333"
And I get this error:
malformed array literal: \"33332a37-f01c-4195-9360-268136725b06\"
I understand that moving the single element out of an array is probably useful more often than not π but is there a smart way to work around this?
- MO
I did try to wrap them in an or, doing both
_eq
and_in
but that just makes both scenarios fail - PI
could you try
companies.companyId[]
? - MO
that worked!! thanks!
- MO
what is this syntax called?
- PI
jsonata - but the way we are using it is similar to jmespath, which I find nicer and is way more popular
https://jsonata.org/
https://jmespath.org/ - MO
awesome, thanks! will have a look at those, would all the functionality be available?
- PI
unfortunately not, only the
.
and[]
operators. If interested in extending it a bit further don't hesitate to drop a feature request on GitHub or reach out to me through DM - MO
Ok, makes sense.
[]
solved my case for now, but will do if something comes up! - EL
Nice. I didn't know about this, we should document it.
Last active 4 months ago
10 replies
5 views