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

Relationships on logical models #9893

Open rbolink opened 1 year ago

rbolink commented 1 year ago

Is your proposal related to a problem?

It is currently not possible to add relationships to logical models. This makes it impossible to add permissions that check if a relationship exists.

Example:

_Logical model measurements has a field called company_id that defines which company is linked to the measurement. I would like to add a permission to this logical model that checks if the current user has access to data of this company. Normally I would check the company relation of the table (in this case logical model) and check if the user is linked to it. If this is the case the user has access to the data. If it isn't we do not return the data._

Because of this issue I won't be able to use the native query/logical model functionality in a production environment.

Describe the solution you'd like

Adding relationships to logical models and using them in the permission configurations (just like in normal tables).

Describe alternatives you've considered

An alternative would be to add permission configurations to native queries. So permissions would not only be available on logical models, but also on the queries itself. As native queries already have relationship functionality only the permissions have to be added.

theholla commented 8 months ago

One more vote for this feature request. The dev team at my company is interested in using native queries in our production application, specifically for a more robust client experience, ie to (docs):

Write a compatibility layer around tables, making it easier to change your API without breaking existing clients.

However, we can't use native queries at this time because logical models don't support table relationships. We'd need to reference relationships in order to verify that a use has adequate permissions to access the resources.

SamirTalwar commented 7 months ago

Hey folks. Native queries now support table relationships (and have done since v2.33; sorry for the slow messaging):

https://hasura.io/docs/latest/schema/postgres/native-queries/#relationships-with-tables

There isn't Console support, but you can use the API or add the metadata to your YAML and use it with the CLI.

Please give it a shot, and close this issue if it solves your problem!

rbolink commented 7 months ago

@SamirTalwar The issue is about relationships on logical models, not on native queries. As I want to add permissions on a logical model using the relationships linked to it. Is this also possible?

Another option would be to add permissions to native queries as they already support relationships, but I don't think this is possible right?

James-Firth commented 7 months ago

+1 from my team, we've also wanted relationships and permissions on logical models so we can re-use the existing permissions we've set up on tables.