Skip to content

Commit

Permalink
Merge branch 'master' into issue-3365-json-returning-mutation
Browse files Browse the repository at this point in the history
  • Loading branch information
rakeshkky authored Nov 25, 2019
2 parents 58b4a0a + 9dd0606 commit fdb6852
Show file tree
Hide file tree
Showing 65 changed files with 1,184 additions and 283 deletions.
5 changes: 4 additions & 1 deletion cli/commands/migrate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ query_collections: []
remote_schemas: []
tables:
- array_relationships: []
computed_fields: []
configuration:
custom_column_names: {}
custom_root_fields:
Expand Down Expand Up @@ -88,12 +89,14 @@ tables:
select_permissions: []
table: test
update_permissions: []
version: 2
`),
"empty-metadata": []byte(`allowlist: []
functions: []
query_collections: []
remote_schemas: []
tables: []
version: 2
`),
}

Expand Down Expand Up @@ -283,7 +286,7 @@ func mustWriteFile(t testing.TB, dir, file string, body string) {

func compareMetadata(t testing.TB, metadataFile string, actualType string, serverVersion *semver.Version) {
var actualData []byte
c, err := semver.NewConstraint("<= v1.0.0-beta.9")
c, err := semver.NewConstraint("<= v1.0.0-beta.10")
if err != nil {
t.Fatal(err)
}
Expand Down
12 changes: 4 additions & 8 deletions console/src/components/Services/Data/RawSQL/RawSQL.js
Original file line number Diff line number Diff line change
Expand Up @@ -252,9 +252,7 @@ const RawSQL = ({
<h4 className={styles.subheading_text}>SQL Result:</h4>
<div className={styles.tableContainer}>
<table
className={`table table-bordered table-striped table-hover ${
styles.table
} `}
className={`table table-bordered table-striped table-hover ${styles.table} `}
>
<thead>
<tr>{getTableHeadings()}</tr>
Expand Down Expand Up @@ -296,7 +294,7 @@ const RawSQL = ({
<label>
<input
checked={isCascadeChecked}
className={styles.add_mar_right_small}
className={`${styles.add_mar_right_small} ${styles.cursorPointer}`}
id="cascade-checkbox"
type="checkbox"
onChange={() => {
Expand Down Expand Up @@ -331,7 +329,7 @@ const RawSQL = ({
<label>
<input
checked={isTableTrackChecked}
className={styles.add_mar_right_small}
className={`${styles.add_mar_right_small} ${styles.cursorPointer}`}
id="track-checkbox"
type="checkbox"
onChange={dispatchTrackThis}
Expand Down Expand Up @@ -476,9 +474,7 @@ const RawSQL = ({
</div>

<div
className={`${styles.padd_left_remove} ${
styles.add_mar_bottom
} col-xs-8`}
className={`${styles.padd_left_remove} ${styles.add_mar_bottom} col-xs-8`}
>
{getTrackThisSection()}
{getMetadataCascadeSection()}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,7 @@ track_function
--------------

``track_function`` is used to add a custom SQL function to the GraphQL schema.

Currently, only functions which satisfy the following constraints can be exposed over the GraphQL API
(*terminology from* `Postgres docs <https://www.postgresql.org/docs/current/sql-createfunction.html>`__):

- **Function behaviour**: ONLY ``STABLE`` or ``IMMUTABLE``
- **Return type**: MUST be ``SETOF <table-name>``
- **Argument modes**: ONLY ``IN``
Also refer a note :ref:`here <note>`.

Add an SQL function ``search_articles``:

Expand All @@ -40,6 +34,85 @@ Add an SQL function ``search_articles``:
}
}
.. _track_function_v2:

track_function v2
-----------------

Version 2 of ``track_function`` is used to add a custom SQL function to the GraphQL schema with configuration.
Also refer a note :ref:`here <note>`.

Add an SQL function called ``search_articles`` with a Hasura session argument.

.. code-block:: http
POST /v1/query HTTP/1.1
Content-Type: application/json
X-Hasura-Role: admin
{
"type": "track_function",
"version": 2,
"args": {
"function": {
"schema": "public",
"name": "search_articles"
},
"configuration": {
"session_argument": "hasura_session"
}
}
}
.. _track_function_args_syntax_v2:

Args syntax
^^^^^^^^^^^

.. list-table::
:header-rows: 1

* - Key
- Required
- Schema
- Description
* - function
- true
- :ref:`FunctionName <FunctionName>`
- Name of the SQL function
* - configuration
- false
- :ref:`Function Configuration <function_configuration>`
- Configuration for the SQL function

.. _function_configuration:

Function Configuration
^^^^^^^^^^^^^^^^^^^^^^

.. list-table::
:header-rows: 1

* - Key
- Required
- Schema
- Description
* - session_argument
- false
- `String`
- Function argument which accepts session info JSON

.. _note:

.. note::

Currently, only functions which satisfy the following constraints can be exposed over the GraphQL API
(*terminology from* `Postgres docs <https://www.postgresql.org/docs/current/sql-createfunction.html>`__):

- **Function behaviour**: ONLY ``STABLE`` or ``IMMUTABLE``
- **Return type**: MUST be ``SETOF <table-name>``
- **Argument modes**: ONLY ``IN``

.. _untrack_function:

untrack_function
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,11 @@ The various types of queries are listed in the following table:
- 1
- Add an SQL function

* - :ref:`track_function`
- :ref:`track_function_args <track_function_args_syntax_v2>`
- 2
- Add an SQL function with configuration

* - :ref:`untrack_function`
- :ref:`FunctionName <FunctionName>`
- 1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,10 @@ Args syntax
- false
- Boolean
- When set to ``false``, the sql is executed without checking metadata dependencies.
* - read_only
- false
- Boolean
- When set to ``true``, the query will be run in ``READ ONLY`` transaction access mode which means only ``select`` queries will be successful. This flag ensures that the GraphQL schema is not modified and is hence highly performant.

Response
^^^^^^^^
Expand Down
9 changes: 8 additions & 1 deletion docs/graphql/manual/guides/integrations/auth0-jwt.rst
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,9 @@ You don't need to integrate your UI with auth0 for testing. You can follow the s
:class: no-shadow
:alt: Auth0 login page

.. note::
In case the above method gives a callback error (with ``access_denied`` in log), try disabling OIDC Conformant setting (https://auth0.com/docs/api-auth/tutorials/adoption/oidc-conformant) under Advanced Settings -> OAuth.

3. After successfully logging in, you will be redirected to ``https://localhost:3000/callback#xxxxxxxx&id_token=yyyyyyy``. This page may be a 404 if you don't have a UI running on localhost:3000.

.. image:: https://graphql-engine-cdn.hasura.io/img/auth0-localhost-callback-404.png
Expand All @@ -82,7 +85,6 @@ You don't need to integrate your UI with auth0 for testing. You can follow the s

**Save this JWT token value so that we can use it later to test authorization using the Hasura console.**

**Note**: In case the above method gives an error, try disabling OIDC Conformant setting (https://auth0.com/docs/api-auth/tutorials/adoption/oidc-conformant) under Advanced Settings -> OAuth.

Configure Hasura to use Auth0 Keys
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Expand Down Expand Up @@ -201,3 +203,8 @@ That’s it! This rule will be triggered on every successful signup/login and sy
.. note::

We need to use an ``upsert`` operation here because social logins do not distinguish between sign-up and login. Hence, we need to run this rule every time a successful login is made and do nothing if the user already exists.


.. admonition:: Local dev with Auth0 rules

The sync step will require a reachable endpoint to Hasura and this is not possible in localhost. You can use `ngrok <https://ngrok.com/>`_ or similar services to expose your locally running Hasura with a public endpoint temporarily.
24 changes: 20 additions & 4 deletions docs/graphql/manual/hasura-cli/install-hasura-cli.rst
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ Installing the Hasura CLI
:depth: 1
:local:

Install
-------
Install a binary globally
-------------------------

.. global-tabs::

Expand Down Expand Up @@ -63,9 +63,25 @@ Install
Download the binary ``cli-hasura-windows-amd64.exe`` available under ``Assets`` of the latest release
from the GitHub release page: https://github.com/hasura/graphql-engine/releases

Rename the downloaded file to ``hasura``.
Rename the downloaded file to ``hasura``.
You can add the path to the environment variable ``PATH`` for making ``hasura`` accessible globally.

Install through npm
-------------------

Hasura CLI is available as an npm package that is independently maintained by some members of the community.
It can be beneficial to use the npm package if you want a version-fixed cli dedicated to your node project.
You can find usage details in the `original repository <https://github.com/jjangga0214/hasura-cli>`_.

.. code-block:: bash
# install as a devDependency of your project
npm install --save-dev hasura-cli
# or install globally on your system
npm install --global hasura-cli
(Optional) Add shell completion
-------------------------------

To add command auto completion in the shell, refer to :ref:`hasura completion <hasura_completion>`.
To add command auto completion in the shell, refer to :ref:`hasura completion <hasura_completion>`.
20 changes: 19 additions & 1 deletion docs/graphql/manual/hasura-cli/uninstall-hasura-cli.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,11 @@ Uninstalling the Hasura CLI
:depth: 1
:local:

To uninstall the Hasura CLI you just need to delete the binary file from its installation location.
Uninstall a binary
------------------

If you installed the binary directly on your system (probably through shell script),
delete the binary file from its installation location.

.. code-block:: bash
Expand All @@ -16,3 +20,17 @@ To uninstall the Hasura CLI you just need to delete the binary file from its ins
# use sudo if required
$ rm /usr/local/bin/hasura
Uninstall an npm package
------------------------

If you installed the CLI as an npm package, use npm (or yarn).

.. code-block:: bash
# if installed as a project dependency
npm uninstall hasura-cli
# if installed as a global package
npm uninstall --global hasura-cli
45 changes: 45 additions & 0 deletions docs/graphql/manual/queries/custom-functions.rst
Original file line number Diff line number Diff line change
Expand Up @@ -395,6 +395,51 @@ Search nearby landmarks with ``distance_kms`` default value which is 2 kms:
}


Accessing Hasura session variables in custom functions
******************************************************

Use the v2 :ref:`track_function <track_function_v2>` to add a function by defining a session argument.
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.

.. code-block:: plpgsql
-- single text column table
CREATE TABLE text_result(
result text
);
-- simple function which returns the hasura role
-- where 'hasura_session' will be session argument
CREATE FUNCTION get_session_role(hasura_session json)
RETURNS SETOF text_result AS $$
SELECT q.* FROM (VALUES (hasura_session ->> 'x-hasura-role')) q
$$ LANGUAGE sql STABLE;
.. graphiql::
:view_only:
:query:
query {
get_session_role {
result
}
}
:response:
{
"data": {
"get_session_role": [
{
"result": "admin"
}
]
}
}

.. note::

The specified session argument will not be included in the ``<function-name>_args`` input object in the GraphQL schema.

Permissions for custom function queries
---------------------------------------

Expand Down
Loading

0 comments on commit fdb6852

Please sign in to comment.