graphjin
graphjin copied to clipboard
CRUD roles inheriting
Let's take the example config here:
roles:
- name: user
tables:
- name: products
query:
filters: ["{ user_id: { eq: $user_id } }"]
insert:
filters: ["{ user_id: { eq: $user_id } }"]
update:
filters: ["{ user_id: { eq: $user_id } }"]
As you can see we're repeating multiple times the string:
["{ user_id: { eq: $user_id } }"]
It would be amazing to have something like:
roles:
- name: user
tables:
- name: products
crud:
filters: ["{ user_id: { eq: $user_id } }"]
query:
# here it is inherited crud's "filters"
insert:
# here it is inherited crud's "filters"
update:
# here it is inherited crud's "filters"
And not just for filters: any!
(And the same in SuperGraph as a library Golang config, of course.)
Don't you think, @dosco?
I don't think you need filters: ["{ user_id: { eq: $user_id } }"] for insert the returned values will be limited to what you have inserted. See the below example
tables:
- name: me
table: users
roles:
- name: user
tables:
- name: me
query:
filters: ["{ id: { eq: $user_id } }", "{ disabled: { neq: true } }"]
update:
filters: ["{ id: { eq: $user_id } }", "{ disabled: { neq: true } }"]
presets:
- updated_at: "now"
- name: posts
insert:
presets:
- user_id: "$user_id"
- created_at: "now"
- updated_at: "now"
Ok. Understood. I can close this but I will leave it open until we document the "preset" that I can't find anywhere.
But there is also this other case:
Roles: []core.Role{
{
Name: "user",
Tables: []core.RoleTable{
{
Name: "players",
Query: &core.Query{
Filters: []string{
"{ account_id: { _eq: $account_id } }",
},
},
},
{
Name: "teams",
Query: &core.Query{
Filters: []string{
"{ account_id: { _eq: $account_id } }",
},
},
},
{
Name: "games",
Query: &core.Query{
Filters: []string{
"{ account_id: { _eq: $account_id } }",
},
},
},
},
},
},
Is there a way to avoid the same line for each table?
"{ account_id: { _eq: $account_id } }"
Not at the moment but should be an easy thing to add.