graphjin icon indicating copy to clipboard operation
graphjin copied to clipboard

CRUD roles inheriting

Open frederikhors opened this issue 5 years ago • 4 comments

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?

frederikhors avatar Jun 28 '20 23:06 frederikhors

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"

dosco avatar Jun 30 '20 04:06 dosco

Ok. Understood. I can close this but I will leave it open until we document the "preset" that I can't find anywhere.

frederikhors avatar Jul 01 '20 22:07 frederikhors

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 } }"

frederikhors avatar Jul 01 '20 23:07 frederikhors

Not at the moment but should be an easy thing to add.

dosco avatar Jul 02 '20 13:07 dosco