hasura / graphql-engine

Blazing fast, instant realtime GraphQL APIs on your DB with fine grained access control, also trigger webhooks on database events.
https://hasura.io
Apache License 2.0
31.16k stars 2.76k forks source link

How to create a relation with two column and one being a literal string? #5535

Closed c19 closed 4 years ago

c19 commented 4 years ago

Table schema looks like this:

Table security_groups 
column id int;

Table rules
column id int;
column cidr varchar;
column type varchar; // ingress or egress
column parent_id reference sercurity_groups(id); // a rule belong to a security_group.

And I wish to create a relation that enables this query:

query {
  security_groups {
     ingress_rules { // return all rules of this security_group and type == "ingress"
       cidr
     }
     egress_rules { // return all rules of this security_group and type == "egress"
       cidr
     }
  }
}

Which means the following relations:

Array relations on security_groups:
ingress_rules
rules . ( id, type )  → security_groups . ( parent_id, "ingress" )

egress_rules
rules . ( id, type )  → security_groups . ( parent_id, "egress" )

unfortunately from the hasura console, we can only select column to bind relations. not literals. But I thinks this is viable.

tirumaraiselvan commented 4 years ago

Closing this as dupe of https://github.com/hasura/graphql-engine/issues/5330