-
Notifications
You must be signed in to change notification settings - Fork 28
/
Copy pathdemo.sql
48 lines (41 loc) · 1.2 KB
/
demo.sql
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
\set QUIET true
\set ON_ERROR_ROLLBACK 1
\set ON_ERROR_STOP true
\include_relative graphql.sql
\include_relative fb/schema.sql
\include_relative fb/data.sql
\x auto
\C Users:
SELECT * FROM "user";
\C Friendships:
SELECT friendship.*, l._||' -> '||r._ AS who FROM friendship,
LATERAL (SELECT full_name FROM "user" WHERE first = id) AS l(_),
LATERAL (SELECT full_name FROM "user" WHERE second = id) AS r(_);
--- Remove the table label.
\C
DO $$
DECLARE
graphql_q text = E'user("f3411edc-e1d0-452a-bc19-b42c0d5a0e36") {\n'
' full_name,\n'
' friendship\n'
'}';
--graphql_q text = E'user("f3411edc-e1d0-452a-bc19-b42c0d5a0e36") {\n'
-- ' full_name,\n'
-- ' friendship { full_name }\n'
-- '}';
sql_q text;
result json;
msg text;
BEGIN
RAISE INFO E'GraphQL to parse:\n%\n', graphql_q;
SELECT * INTO STRICT sql_q FROM graphql.to_sql(graphql_q);
RAISE INFO E'SQL that will be run:\n%\n', sql_q;
result := graphql.run(graphql_q);
RAISE INFO E'Result:\n%\n', result;
END
$$;
BEGIN;
SET LOCAL client_min_messages TO ERROR;
DROP SCHEMA graphql CASCADE;
DROP SCHEMA fb CASCADE;
END;