Graphql-engine: accessing session variables in function via computed field

Created on 6 Feb 2020  路  8Comments  路  Source: hasura/graphql-engine

It would be really cool to be able to define a function like

CREATE OR REPLACE FUNCTION article_liked(article_row article, hasura_session json)
RETURNS boolean AS $$
  SELECT EXISTS (
    SELECT 1
    FROM liked_article A
    WHERE A.user_id = hasura_session ->> 'x-hasura-user-id' AND A.article_id = article_row.id
  );
$$ LANGUAGE sql STABLE;

and use it via a computed field without any args.

I know that in order to get hasura_session injected the function needs to be tracked, but tracked functions only support SETOF return types.

I can dive in a try to do a PR if there's interest in this kind of functionality.

server enhancement high

Most helpful comment

Is there any update on this? Or any workaround currently?

All 8 comments

@rikinsk @marionschleifer there are lots of powerful use-cases here exactly like the one @sincraianul mentioned. We should add this to our docs as well and we could talk about this as a XByViewer (likedByViewer) feature that folks need to add.

@sincraianul would absolutely love a PR for this feature. @rakeshkky should be able to help and guide you :)

@coco98 Wow, thanks for the really positive response! I'll get started right away.

Also really looking forward to this implementation! It would be extremely powerful! Good luck!

Is there any update on this? Or any workaround currently?

We love this feature very much.
This will be extremely useful with regards to data privacy (GDPR, PPI), e.g. We will be able to decrypt privacy information for appropriate user.
It would be nice if you add this feature to the next release.

Thanks

Any update on this? Really needed

Looking forward to this as well!

Is there any other way to either implement the liked property or use the hasura_session inside a psql function in v1.2.2?

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Fortidude picture Fortidude  路  3Comments

macalinao picture macalinao  路  3Comments

EmrysMyrddin picture EmrysMyrddin  路  3Comments

lishine picture lishine  路  3Comments

cpursley picture cpursley  路  3Comments