mirror of
https://github.com/hasura/graphql-engine.git
synced 2024-12-17 04:24:35 +03:00
312e56dfa6
GitOrigin-RevId: fbf99816a70e666bb9b02fca92a0ee7d419cdff8
117 lines
3.4 KiB
YAML
117 lines
3.4 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 ''
|
|
);
|
|
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;
|
|
CREATE FUNCTION volatile_func1()
|
|
RETURNS SETOF "user" AS $$
|
|
SELECT * FROM "user" ORDER BY id
|
|
$$ LANGUAGE sql VOLATILE;
|
|
CREATE FUNCTION stable_func1()
|
|
RETURNS SETOF "user" AS $$
|
|
SELECT * FROM "user" ORDER BY id
|
|
$$ LANGUAGE sql STABLE;
|
|
CREATE FUNCTION volatile_func2()
|
|
RETURNS SETOF "user" AS $$
|
|
SELECT * FROM "user" ORDER BY id
|
|
$$ LANGUAGE sql VOLATILE;
|
|
CREATE FUNCTION stable_func2()
|
|
RETURNS SETOF "user" AS $$
|
|
SELECT * FROM "user" ORDER BY id
|
|
$$ LANGUAGE sql STABLE;
|
|
CREATE FUNCTION add_to_score_by_user_id(hasura_session json, id int, increment integer default 1)
|
|
RETURNS "user" AS $$
|
|
UPDATE "user"
|
|
SET score = score + increment
|
|
WHERE id = id
|
|
RETURNING id,
|
|
name,
|
|
score,
|
|
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
|
|
|
|
- type: track_function
|
|
version: 2
|
|
args:
|
|
function:
|
|
schema: public
|
|
name: add_to_score_by_user_id
|
|
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
|
|
- 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
|