mirror of
https://github.com/hasura/graphql-engine.git
synced 2024-12-27 01:15:51 +03:00
118 lines
3.2 KiB
YAML
118 lines
3.2 KiB
YAML
|
# Test VOLATILE SQL functions exposed as top-level fields under the mutation root field
|
||
|
# (#1514)
|
||
|
type: bulk
|
||
|
args:
|
||
|
|
||
|
# test functions having multiple defaults
|
||
|
- type: run_sql
|
||
|
args:
|
||
|
sql: |
|
||
|
CREATE TABLE "user" (
|
||
|
id SERIAL PRIMARY KEY,
|
||
|
name TEXT NOT NULL,
|
||
|
score INTEGER,
|
||
|
/* We just return the session vars as this column from our function
|
||
|
* to show they're passed through properly.
|
||
|
*
|
||
|
* NOTE: with the addition of function "tracking" we probably want to
|
||
|
* logically be defining permissions on composite types (which might
|
||
|
* or might not have been created implicitly in a CREATE TABLE).
|
||
|
*
|
||
|
* See: https://github.com/hasura/graphql-engine-internal/issues/502
|
||
|
*/
|
||
|
role_echo TEXT DEFAULT ''
|
||
|
);
|
||
|
|
||
|
# Adds a value (defaulting to 1) to users matching 'search', returning updated
|
||
|
# rows and echoing the hasura session vars.
|
||
|
- type: run_sql
|
||
|
args:
|
||
|
sql: |
|
||
|
CREATE FUNCTION add_to_score(hasura_session json, search text, increment integer default 1)
|
||
|
RETURNS SETOF "user" AS $$
|
||
|
UPDATE "user"
|
||
|
SET score = score + increment
|
||
|
WHERE name ilike ('%' || search || '%')
|
||
|
RETURNING id,
|
||
|
name,
|
||
|
score,
|
||
|
/* NOTE: other fields may be added to hasura_session
|
||
|
* depending on the flavor of test run on CI, e.g.
|
||
|
* x-hasura-auth-mode: webhook, so filter just x-hasura-role
|
||
|
*/
|
||
|
hasura_session->>'x-hasura-role' AS role_echo
|
||
|
$$ LANGUAGE sql VOLATILE;
|
||
|
|
||
|
- type: track_table
|
||
|
args:
|
||
|
name: user
|
||
|
schema: public
|
||
|
|
||
|
- type: track_function
|
||
|
version: 2
|
||
|
args:
|
||
|
function:
|
||
|
schema: public
|
||
|
name: add_to_score
|
||
|
configuration:
|
||
|
exposed_as: mutation
|
||
|
session_argument: hasura_session
|
||
|
|
||
|
|
||
|
# We'll use this to check that permissions on "user" table are applied to the
|
||
|
# return set of the tracked function:
|
||
|
- type: create_select_permission
|
||
|
args:
|
||
|
table: user
|
||
|
role: anonymous
|
||
|
permission:
|
||
|
filter: {}
|
||
|
columns:
|
||
|
- name
|
||
|
- score
|
||
|
|
||
|
|
||
|
# A few unimportant functions for smoke tests
|
||
|
- type: run_sql
|
||
|
args:
|
||
|
sql: |
|
||
|
CREATE FUNCTION volatile_func1()
|
||
|
RETURNS SETOF "user" AS $$
|
||
|
SELECT * FROM "user" ORDER BY id
|
||
|
$$ LANGUAGE sql VOLATILE;
|
||
|
- type: run_sql
|
||
|
args:
|
||
|
sql: |
|
||
|
CREATE FUNCTION stable_func1()
|
||
|
RETURNS SETOF "user" AS $$
|
||
|
SELECT * FROM "user" ORDER BY id
|
||
|
$$ LANGUAGE sql STABLE;
|
||
|
- type: run_sql
|
||
|
args:
|
||
|
sql: |
|
||
|
CREATE FUNCTION volatile_func2()
|
||
|
RETURNS SETOF "user" AS $$
|
||
|
SELECT * FROM "user" ORDER BY id
|
||
|
$$ LANGUAGE sql VOLATILE;
|
||
|
- type: run_sql
|
||
|
args:
|
||
|
sql: |
|
||
|
CREATE FUNCTION stable_func2()
|
||
|
RETURNS SETOF "user" AS $$
|
||
|
SELECT * FROM "user" ORDER BY id
|
||
|
$$ LANGUAGE sql STABLE;
|
||
|
|
||
|
# Infer that function should be a mutation from VOLATILE, if exposed_as
|
||
|
- version: 2
|
||
|
type: track_function
|
||
|
args:
|
||
|
function: volatile_func2
|
||
|
|
||
|
# Volatile function as query
|
||
|
- version: 2
|
||
|
type: track_function
|
||
|
args:
|
||
|
function: volatile_func1
|
||
|
configuration:
|
||
|
exposed_as: query
|