Skip to content

Commit 09dd20a

Browse files
oliricedarora
authored andcommitted
add pg_graphql tests
1 parent 7d289ba commit 09dd20a

File tree

2 files changed

+476
-0
lines changed

2 files changed

+476
-0
lines changed

nix/tests/expected/pg_graphql.out

Lines changed: 258 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,258 @@
1+
begin;
2+
create table account(
3+
id serial primary key,
4+
email varchar(255) not null,
5+
priority int,
6+
status text default 'active'
7+
);
8+
create table blog(
9+
id serial primary key,
10+
owner_id integer not null references account(id)
11+
);
12+
comment on table blog is e'@graphql({"totalCount": {"enabled": true}})';
13+
-- Make sure functions still work
14+
create function _echo_email(account)
15+
returns text
16+
language sql
17+
as $$ select $1.email $$;
18+
/*
19+
Literals
20+
*/
21+
select graphql.resolve($$
22+
mutation {
23+
insertIntoAccountCollection(objects: [
24+
{ email: "[email protected]", priority: 1 },
25+
{ email: "[email protected]" }
26+
]) {
27+
affectedCount
28+
records {
29+
id
30+
status
31+
echoEmail
32+
blogCollection {
33+
totalCount
34+
}
35+
}
36+
}
37+
}
38+
$$);
39+
resolve
40+
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
41+
{"data": {"insertIntoAccountCollection": {"records": [{"id": 1, "status": "active", "echoEmail": "[email protected]", "blogCollection": {"totalCount": 0}}, {"id": 2, "status": "active", "echoEmail": "[email protected]", "blogCollection": {"totalCount": 0}}], "affectedCount": 2}}}
42+
(1 row)
43+
44+
select graphql.resolve($$
45+
mutation {
46+
insertIntoBlogCollection(objects: [{
47+
ownerId: 1
48+
}]) {
49+
records {
50+
id
51+
owner {
52+
id
53+
}
54+
}
55+
}
56+
}
57+
$$);
58+
resolve
59+
--------------------------------------------------------------------------------------
60+
{"data": {"insertIntoBlogCollection": {"records": [{"id": 1, "owner": {"id": 1}}]}}}
61+
(1 row)
62+
63+
-- Override a default on status with null
64+
select graphql.resolve($$
65+
mutation {
66+
insertIntoAccountCollection(objects: [
67+
{ email: "[email protected]", status: null },
68+
]) {
69+
affectedCount
70+
records {
71+
email
72+
status
73+
}
74+
}
75+
}
76+
$$);
77+
resolve
78+
------------------------------------------------------------------------------------------------------------------------
79+
{"data": {"insertIntoAccountCollection": {"records": [{"email": "[email protected]", "status": null}], "affectedCount": 1}}}
80+
(1 row)
81+
82+
/*
83+
Variables
84+
*/
85+
select graphql.resolve($$
86+
mutation newAccount($emailAddress: String) {
87+
xyz: insertIntoAccountCollection(objects: [
88+
{ email: $emailAddress },
89+
{ email: "[email protected]" }
90+
]) {
91+
affectedCount
92+
records {
93+
id
94+
email
95+
}
96+
}
97+
}
98+
$$,
99+
variables := '{"emailAddress": "[email protected]"}'::jsonb
100+
);
101+
resolve
102+
--------------------------------------------------------------------------------------------------------------------------------
103+
{"data": {"xyz": {"records": [{"id": 4, "email": "[email protected]"}, {"id": 5, "email": "[email protected]"}], "affectedCount": 2}}}
104+
(1 row)
105+
106+
-- Variable override of default with null results in null
107+
select graphql.resolve($$
108+
mutation newAccount($status: String) {
109+
xyz: insertIntoAccountCollection(objects: [
110+
{ email: "[email protected]", status: $status}
111+
]) {
112+
affectedCount
113+
records {
114+
email
115+
status
116+
}
117+
}
118+
}
119+
$$,
120+
variables := '{"status": null}'::jsonb
121+
);
122+
resolve
123+
------------------------------------------------------------------------------------------------
124+
{"data": {"xyz": {"records": [{"email": "[email protected]", "status": null}], "affectedCount": 1}}}
125+
(1 row)
126+
127+
-- Skipping variable override of default results in default
128+
select graphql.resolve($$
129+
mutation newAccount($status: String) {
130+
xyz: insertIntoAccountCollection(objects: [
131+
{ email: "[email protected]", status: $status},
132+
]) {
133+
affectedCount
134+
records {
135+
email
136+
status
137+
}
138+
}
139+
}
140+
$$,
141+
variables := '{}'::jsonb
142+
);
143+
resolve
144+
------------------------------------------------------------------------------------------------
145+
{"data": {"xyz": {"records": [{"email": "[email protected]", "status": "active"}], "affectedCount": 1}}}
146+
(1 row)
147+
148+
select graphql.resolve($$
149+
mutation newAccount($acc: AccountInsertInput!) {
150+
insertIntoAccountCollection(objects: [$acc]) {
151+
affectedCount
152+
records {
153+
id
154+
email
155+
}
156+
}
157+
}
158+
$$,
159+
variables := '{"acc": {"email": "[email protected]"}}'::jsonb
160+
);
161+
resolve
162+
-----------------------------------------------------------------------------------------------------------------
163+
{"data": {"insertIntoAccountCollection": {"records": [{"id": 8, "email": "[email protected]"}], "affectedCount": 1}}}
164+
(1 row)
165+
166+
select graphql.resolve($$
167+
mutation newAccounts($acc: [AccountInsertInput!]!) {
168+
insertIntoAccountCollection(objects: $accs) {
169+
affectedCount
170+
records {
171+
id
172+
email
173+
}
174+
}
175+
}
176+
$$,
177+
variables := '{"accs": [{"email": "[email protected]"}]}'::jsonb
178+
);
179+
resolve
180+
-----------------------------------------------------------------------------------------------------------------
181+
{"data": {"insertIntoAccountCollection": {"records": [{"id": 9, "email": "[email protected]"}], "affectedCount": 1}}}
182+
(1 row)
183+
184+
-- Single object coerces to a list
185+
select graphql.resolve($$
186+
mutation {
187+
insertIntoBlogCollection(objects: {ownerId: 1}) {
188+
affectedCount
189+
}
190+
}
191+
$$);
192+
resolve
193+
--------------------------------------------------------------
194+
{"data": {"insertIntoBlogCollection": {"affectedCount": 1}}}
195+
(1 row)
196+
197+
/*
198+
Errors
199+
*/
200+
-- Field does not exist
201+
select graphql.resolve($$
202+
mutation createAccount($acc: AccountInsertInput) {
203+
insertIntoAccountCollection(objects: [$acc]) {
204+
affectedCount
205+
records {
206+
id
207+
email
208+
}
209+
}
210+
}
211+
$$,
212+
variables := '{"acc": {"doesNotExist": "other"}}'::jsonb
213+
);
214+
resolve
215+
---------------------------------------------------------------------------------------------------------------------
216+
{"data": null, "errors": [{"message": "Input for type AccountInsertInput contains extra keys [\"doesNotExist\"]"}]}
217+
(1 row)
218+
219+
-- Wrong input type (list of string, not list of object)
220+
select graphql.resolve($$
221+
mutation {
222+
insertIntoBlogCollection(objects: ["not an object"]) {
223+
affectedCount
224+
}
225+
}
226+
$$);
227+
resolve
228+
-----------------------------------------------------------------------------------
229+
{"data": null, "errors": [{"message": "Invalid input for BlogInsertInput type"}]}
230+
(1 row)
231+
232+
-- objects argument is missing
233+
select graphql.resolve($$
234+
mutation {
235+
insertIntoBlogCollection {
236+
affectedCount
237+
}
238+
}
239+
$$);
240+
resolve
241+
---------------------------------------------------------------------------
242+
{"data": null, "errors": [{"message": "Invalid input for NonNull type"}]}
243+
(1 row)
244+
245+
-- Empty call
246+
select graphql.resolve($$
247+
mutation {
248+
insertIntoBlogCollection(objects: []) {
249+
affectedCount
250+
}
251+
}
252+
$$);
253+
resolve
254+
--------------------------------------------------------------------------------------------
255+
{"data": null, "errors": [{"message": "At least one record must be provided to objects"}]}
256+
(1 row)
257+
258+
rollback;

0 commit comments

Comments
 (0)