New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
functions can access session info via input arg (close #2322) #3143
Conversation
Deploy preview for hasura-docs ready! Built with commit 99664ce |
24aceda
to
c8dc756
Compare
Review app for commit 14c58e3 deployed to Heroku: https://hge-ci-pull-3143.herokuapp.com |
14c58e3
to
322b814
Compare
Review app for commit 322b814 deployed to Heroku: https://hge-ci-pull-3143.herokuapp.com |
Resolve Conflicts: server/src-lib/Hasura/GraphQL/Resolve/Select.hs server/src-lib/Hasura/GraphQL/Resolve/Types.hs server/src-lib/Hasura/GraphQL/Schema.hs server/src-lib/Hasura/RQL/DDL/Schema/Cache.hs server/src-lib/Hasura/RQL/DDL/Schema/Function.hs server/src-lib/Hasura/RQL/Types/Catalog.hs server/src-lib/Hasura/RQL/Types/Common.hs server/src-lib/Hasura/RQL/Types/SchemaCache.hs server/src-rsr/catalog_metadata.sql server/src-rsr/migrations/25_to_26.sql
Review app for commit afbe0eb deployed to Heroku: https://hge-ci-pull-3143.herokuapp.com |
Resolve Conflicts: server/src-lib/Hasura/RQL/DDL/Metadata.hs server/src-lib/Hasura/RQL/DDL/Schema/Cache.hs server/src-lib/Hasura/RQL/DDL/Schema/Function.hs server/src-lib/Hasura/RQL/Types/Catalog.hs server/src-rsr/catalog_metadata.sql
Review app for commit b3bff20 deployed to Heroku: https://hge-ci-pull-3143.herokuapp.com |
Review app for commit 110f0d2 deployed to Heroku: https://hge-ci-pull-3143.herokuapp.com |
Review app for commit 18d6625 deployed to Heroku: https://hge-ci-pull-3143.herokuapp.com |
Cross-posting a comment I made on slack, since that discussion never really went anywhere:
@rakeshkky, do you have any thoughts on whether or not doing something like that would work/is a good idea? The overhead of configuring this for every function individually seems a little high to me, but maybe I’m overreacting. |
@lexi-lambda Now, we may avoid configuring the SQL functions and auto derive the session argument using As a developer, IMO, I'd like to define things explicitly. While tracking a SQL functions I'd always like to specify what argument in my function accepts the session information JSON 🙂. Auto deriving may affect the functions which are already tracked (if a function already has |
Review app for commit ba1b335 deployed to Heroku: https://hge-ci-pull-3143.herokuapp.com |
Review app for commit ef9ca75 deployed to Heroku: https://hge-ci-pull-3143.herokuapp.com |
ef9ca75
to
42ec624
Compare
Review app for commit 42ec624 deployed to Heroku: https://hge-ci-pull-3143.herokuapp.com |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I left one comment. Otherwise, it looks good 🙂
The session argument will be a JSON object where keys are session variable names (in lower case) and values are strings. | ||
Use the ``->>`` JSON operator to fetch the value of a session variable as shown in the following example. | ||
|
||
.. note:: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we have the note in the end of this section? When we say in the following example
, then the example should follow immediately.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
💯
Review app for commit 99664ce deployed to Heroku: https://hge-ci-pull-3143.herokuapp.com |
Review app https://hge-ci-pull-3143.herokuapp.com is deleted |
Description
We can access session information (in JSON) in a transaction using
current_setting('hasura.user')
when queries are run in a transaction. But subscriptions are not run in a transaction any more. This PR supports tracking SQL functions by configuring an input session argument so as to access the session variables JSON through it.Metadata exported by the server (through
export_metadata
) is versioned via a top-level fieldversion
whose value is either1
or2
. Ifversion
field is absent (metadata exported by previous server versions) then it is considered asversion: 1
. In version2
, the exported metadata functions are a list of JSON objects withfunction
andconfiguration
field.A sample metadata yaml exported.
See preview docs to learn more about accessing session variables in SQL functions.
Affected components
Related Issues
close #2322
Solution and Design
track_function
query type is defined to facilitate users to specify the configuration with session argument. An example request as followsversion
key. The server exports metadata with version2
and accepts metadata of versions1
and2
.Steps to test and verify
Follow the example here
Limitations, known bugs & workarounds