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.13k stars 2.76k forks source link

Apply PostgreSQL function on mutation/query #4917

Open sanderhahn opened 4 years ago

sanderhahn commented 4 years ago

Sometimes you want to store and retrieve sensitive data such as passwords using pgcrypto that is already installed by default. People find this difficult to do using triggers, maybe Hasura could allow configuring a function or snippet to be performed on the data on mutations and queries in the metadata. For instance:

create table account (
    email text primary key,
    password text
);

insert into account (email, password) values ('you@domain.com', crypt('password', gen_salt('bf')));

select * from account where email = 'you@domain.com' and crypt('password', password) = password;

The snippets would be:

mutation password -> crypt('password', gen_salt('bf'))
query password -> crypt('password', password) = password

Query would override _eq or maybe its possible to create a custom operator _eq_crypt. Snippets are flexible, but another simpler option would be marking the field as password field in the metadata and support this way of mutation/query without exposing the underlying sql.

mentatxx commented 3 years ago

Yeah, looking forward to run functions via mutations. It is not cool to create actions/lambdas to just call a function.

Volatile functions for queries are not intended to modify data

jadiaheno commented 3 years ago

+1 for this. Anything new on this? It will basically help me not to create actions for login/signin/forgot-password

Zerebokep commented 2 years ago

Any update on this?

rayhantr commented 1 year ago

Any update?

image