-
-
Notifications
You must be signed in to change notification settings - Fork 106
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
354 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,216 @@ | ||
begin; | ||
create table account( | ||
id int primary key, | ||
email varchar(255) not null, | ||
priority int, | ||
status text default 'active' | ||
); | ||
/* | ||
Literals | ||
*/ | ||
select jsonb_pretty(graphql.resolve($$ | ||
mutation { | ||
insertIntoAccountCollection( | ||
objects: [ | ||
{ id: 1, email: "foo@barsley.com", priority: 1 }, | ||
{ id: 2, email: "bar@foosworth.com" } | ||
] | ||
onConflict: { | ||
constraint: account_pkey, | ||
updateFields: [email, priority, status], | ||
} | ||
) { | ||
affectedCount | ||
records { | ||
id | ||
priority | ||
} | ||
} | ||
} | ||
$$)); | ||
jsonb_pretty | ||
--------------------------------------------------- | ||
{ + | ||
"data": { + | ||
"insertIntoAccountCollection": { + | ||
"records": [ + | ||
{ + | ||
"id": 1, + | ||
"email": "foo@barsley.com", + | ||
"priority": 1 + | ||
}, + | ||
{ + | ||
"id": 2, + | ||
"email": "bar@foosworth.com",+ | ||
"priority": null + | ||
} + | ||
], + | ||
"affectedCount": 2 + | ||
} + | ||
} + | ||
} | ||
(1 row) | ||
|
||
-- Email should update. Priority should not | ||
-- 1 row affected | ||
select jsonb_pretty(graphql.resolve($$ | ||
mutation { | ||
insertIntoAccountCollection( | ||
objects: [ | ||
{ id: 1, email: "new@email.com", priority: 2 }, | ||
] | ||
onConflict: { | ||
constraint: account_pkey, | ||
updateFields: [email, status], | ||
} | ||
) { | ||
affectedCount | ||
records { | ||
id | ||
} | ||
} | ||
} | ||
$$)); | ||
jsonb_pretty | ||
---------------------------------------------- | ||
{ + | ||
"data": { + | ||
"insertIntoAccountCollection": { + | ||
"records": [ + | ||
{ + | ||
"id": 1, + | ||
"email": "new@email.com"+ | ||
} + | ||
], + | ||
"affectedCount": 1 + | ||
} + | ||
} + | ||
} | ||
(1 row) | ||
|
||
-- Email and priority should update | ||
-- 2 row affected | ||
select jsonb_pretty(graphql.resolve($$ | ||
mutation { | ||
insertIntoAccountCollection( | ||
objects: [ | ||
{ id: 1, email: "new@email.com", priority: 2 }, | ||
{ id: 2, email: "new@email.com"}, | ||
] | ||
onConflict: { | ||
constraint: account_pkey, | ||
updateFields: [email, status], | ||
} | ||
) { | ||
affectedCount | ||
records { | ||
id | ||
priority | ||
} | ||
} | ||
} | ||
$$)); | ||
jsonb_pretty | ||
----------------------------------------------- | ||
{ + | ||
"data": { + | ||
"insertIntoAccountCollection": { + | ||
"records": [ + | ||
{ + | ||
"id": 1, + | ||
"email": "new@email.com",+ | ||
"priority": 1 + | ||
}, + | ||
{ + | ||
"id": 2, + | ||
"email": "new@email.com",+ | ||
"priority": null + | ||
} + | ||
], + | ||
"affectedCount": 2 + | ||
} + | ||
} + | ||
} | ||
(1 row) | ||
|
||
-- Filter prevents second row update | ||
-- 1 row affected | ||
select jsonb_pretty(graphql.resolve($$ | ||
mutation { | ||
insertIntoAccountCollection( | ||
objects: [ | ||
{ id: 1, email: "third@email.com"}, | ||
{ id: 2, email: "new@email.com"}, | ||
] | ||
onConflict: { | ||
constraint: account_pkey, | ||
updateFields: [email, status], | ||
} | ||
filter: { | ||
id: {id: $ifilt} | ||
} | ||
) { | ||
affectedCount | ||
records { | ||
id | ||
priority | ||
} | ||
} | ||
} | ||
$$)); | ||
jsonb_pretty | ||
----------------------------------------------------------------- | ||
{ + | ||
"data": null, + | ||
"errors": [ + | ||
{ + | ||
"message": "Input contains extra keys [\"filter\"]"+ | ||
} + | ||
] + | ||
} | ||
(1 row) | ||
|
||
-- Variable Filter | ||
-- Only row id=2 updated due to where clause | ||
select jsonb_pretty(graphql.resolve($$ | ||
mutation AccountsFiltered($ifilt: IntFilter!) | ||
insertIntoAccountCollection( | ||
objects: [ | ||
{ id: 1, email: "fourth@email.com"}, | ||
{ id: 2, email: "fourth@email.com"}, | ||
] | ||
onConflict: { | ||
constraint: account_pkey, | ||
updateFields: [email, status], | ||
} | ||
filter: { | ||
id: {id: $ifilt} | ||
} | ||
) { | ||
affectedCount | ||
records { | ||
id | ||
priority | ||
} | ||
} | ||
} | ||
$$, | ||
variables:= '{"ifilt": {"eq": 2}}' | ||
)); | ||
jsonb_pretty | ||
-------------------------------------------------------------------------------------------------------------------------------- | ||
{ + | ||
"errors": [ + | ||
{ + | ||
"message": "query parse error: Parse error at 3:7\nUnexpected `insertIntoAccountCollection[Name]`\nExpected `{`\n"+ | ||
} + | ||
] + | ||
} | ||
(1 row) | ||
|
||
rollback; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,138 @@ | ||
begin; | ||
|
||
create table account( | ||
id int primary key, | ||
email varchar(255) not null, | ||
priority int, | ||
status text default 'active' | ||
); | ||
|
||
/* | ||
Literals | ||
*/ | ||
|
||
select jsonb_pretty(graphql.resolve($$ | ||
mutation { | ||
insertIntoAccountCollection( | ||
objects: [ | ||
{ id: 1, email: "foo@barsley.com", priority: 1 }, | ||
{ id: 2, email: "bar@foosworth.com" } | ||
] | ||
onConflict: { | ||
constraint: account_pkey, | ||
updateFields: [email, priority, status], | ||
} | ||
) { | ||
affectedCount | ||
records { | ||
id | ||
priority | ||
} | ||
} | ||
} | ||
$$)); | ||
|
||
-- Email should update. Priority should not | ||
-- 1 row affected | ||
select jsonb_pretty(graphql.resolve($$ | ||
mutation { | ||
insertIntoAccountCollection( | ||
objects: [ | ||
{ id: 1, email: "new@email.com", priority: 2 }, | ||
] | ||
onConflict: { | ||
constraint: account_pkey, | ||
updateFields: [email, status], | ||
} | ||
) { | ||
affectedCount | ||
records { | ||
id | ||
} | ||
} | ||
} | ||
$$)); | ||
|
||
-- Email and priority should update | ||
-- 2 row affected | ||
select jsonb_pretty(graphql.resolve($$ | ||
mutation { | ||
insertIntoAccountCollection( | ||
objects: [ | ||
{ id: 1, email: "new@email.com", priority: 2 }, | ||
{ id: 2, email: "new@email.com"}, | ||
] | ||
onConflict: { | ||
constraint: account_pkey, | ||
updateFields: [email, status], | ||
} | ||
) { | ||
affectedCount | ||
records { | ||
id | ||
priority | ||
} | ||
} | ||
} | ||
$$)); | ||
|
||
-- Filter prevents second row update | ||
-- 1 row affected | ||
select jsonb_pretty(graphql.resolve($$ | ||
mutation { | ||
insertIntoAccountCollection( | ||
objects: [ | ||
{ id: 1, email: "third@email.com"}, | ||
{ id: 2, email: "new@email.com"}, | ||
] | ||
onConflict: { | ||
constraint: account_pkey, | ||
updateFields: [email, status], | ||
} | ||
filter: { | ||
id: {id: $ifilt} | ||
} | ||
) { | ||
affectedCount | ||
records { | ||
id | ||
priority | ||
} | ||
} | ||
} | ||
$$)); | ||
|
||
-- Variable Filter | ||
-- Only row id=2 updated due to where clause | ||
select jsonb_pretty(graphql.resolve($$ | ||
mutation AccountsFiltered($ifilt: IntFilter!) | ||
insertIntoAccountCollection( | ||
objects: [ | ||
{ id: 1, email: "fourth@email.com"}, | ||
{ id: 2, email: "fourth@email.com"}, | ||
] | ||
onConflict: { | ||
constraint: account_pkey, | ||
updateFields: [email, status], | ||
} | ||
filter: { | ||
id: {id: $ifilt} | ||
} | ||
) { | ||
affectedCount | ||
records { | ||
id | ||
priority | ||
} | ||
} | ||
} | ||
$$, | ||
variables:= '{"ifilt": {"eq": 2}}' | ||
)); | ||
|
||
rollback; |