question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Feature request: using functions with session arguments to define computed columns

See original GitHub issue

This is closely related to #2760 with the same motivation, except that I would like to have a view which transforms (not filters!) a table based on X-Hasura-User-Id. A straightforward solution is to expose session variables in queries under current_setting('hasura.user') similarly to how it’s done in mutations. In fact, the change implementing this is simple:

--- a/server/src-lib/Hasura/GraphQL/Transport/HTTP.hs
+++ b/server/src-lib/Hasura/GraphQL/Transport/HTTP.hs
@@ -50,7 +50,7 @@ runHasuraGQ reqId query userInfo resolvedOp = do
     E.ExOpQuery tx genSql  -> do
       -- log the generated SQL and the graphql query
       liftIO $ logGraphqlQuery logger $ QueryLog query genSql reqId
-      runLazyTx' pgExecCtx tx
+      runLazyTx pgExecCtx $ withUserInfo userInfo tx
     E.ExOpMutation tx -> do
       -- log the graphql query
       liftIO $ logGraphqlQuery logger $ QueryLog query Nothing reqId

Still, I wanted to make sure the idea itself is sound before opening a PR.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:3
  • Comments:8 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
tirumaraiselvancommented, Apr 13, 2020

Yes, this is high up in our priority list. Actually, it was being tracked here: https://github.com/hasura/graphql-engine/issues/3846

I am closing this issue in favour of #3846 (as more eyeballs there)

1reaction
rakeshkkycommented, Nov 21, 2019

@lexi-lambda No. #3143 only support root SQL function queries to access session information. This needs to be done.

Read more comments on GitHub >

github_iconTop Results From Across the Web

accessing session variables in function via computed field
and use it via a computed field without any args. I know that in order to get hasura_session injected the function needs to...
Read more >
Postgres: Computed fields | Hasura GraphQL Docs
Computed fields are virtual values or objects that are dynamically computed and can be queried along with a table/view's columns. Computed fields are...
Read more >
Computed Columns | CockroachDB Docs
A computed column exposes data generated by an expression included in the column definition.
Read more >
ALTER TABLE computed_column_definition (Transact-SQL)
ALTER TABLE computed_column_definition specifies the properties of a computed column that is added to a table by using ALTER TABLE.
Read more >
Is there a way to prevent Scalar UDFs in computed columns ...
Yes if you: are running SQL Server 2014 or later; and; are able to run the query with trace flag 176 active; and;...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found