Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
259 changes: 259 additions & 0 deletions nix/tests/expected/pg_graphql.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,259 @@
begin;
comment on schema public is '@graphql({"inflect_names": true})';
create table account(
id serial primary key,
email varchar(255) not null,
priority int,
status text default 'active'
);
create table blog(
id serial primary key,
owner_id integer not null references account(id)
);
comment on table blog is e'@graphql({"totalCount": {"enabled": true}})';
-- Make sure functions still work
create function _echo_email(account)
returns text
language sql
as $$ select $1.email $$;
/*
Literals
*/
select graphql.resolve($$
mutation {
insertIntoAccountCollection(objects: [
{ email: "[email protected]", priority: 1 },
{ email: "[email protected]" }
]) {
affectedCount
records {
id
status
echoEmail
blogCollection {
totalCount
}
}
}
}
$$);
resolve
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
{"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}}}
(1 row)

select graphql.resolve($$
mutation {
insertIntoBlogCollection(objects: [{
ownerId: 1
}]) {
records {
id
owner {
id
}
}
}
}
$$);
resolve
--------------------------------------------------------------------------------------
{"data": {"insertIntoBlogCollection": {"records": [{"id": 1, "owner": {"id": 1}}]}}}
(1 row)

-- Override a default on status with null
select graphql.resolve($$
mutation {
insertIntoAccountCollection(objects: [
{ email: "[email protected]", status: null },
]) {
affectedCount
records {
email
status
}
}
}
$$);
resolve
------------------------------------------------------------------------------------------------------------------------
{"data": {"insertIntoAccountCollection": {"records": [{"email": "[email protected]", "status": null}], "affectedCount": 1}}}
(1 row)

/*
Variables
*/
select graphql.resolve($$
mutation newAccount($emailAddress: String) {
xyz: insertIntoAccountCollection(objects: [
{ email: $emailAddress },
{ email: "[email protected]" }
]) {
affectedCount
records {
id
email
}
}
}
$$,
variables := '{"emailAddress": "[email protected]"}'::jsonb
);
resolve
--------------------------------------------------------------------------------------------------------------------------------
{"data": {"xyz": {"records": [{"id": 4, "email": "[email protected]"}, {"id": 5, "email": "[email protected]"}], "affectedCount": 2}}}
(1 row)

-- Variable override of default with null results in null
select graphql.resolve($$
mutation newAccount($status: String) {
xyz: insertIntoAccountCollection(objects: [
{ email: "[email protected]", status: $status}
]) {
affectedCount
records {
email
status
}
}
}
$$,
variables := '{"status": null}'::jsonb
);
resolve
------------------------------------------------------------------------------------------------
{"data": {"xyz": {"records": [{"email": "[email protected]", "status": null}], "affectedCount": 1}}}
(1 row)

-- Skipping variable override of default results in default
select graphql.resolve($$
mutation newAccount($status: String) {
xyz: insertIntoAccountCollection(objects: [
{ email: "[email protected]", status: $status},
]) {
affectedCount
records {
email
status
}
}
}
$$,
variables := '{}'::jsonb
);
resolve
------------------------------------------------------------------------------------------------
{"data": {"xyz": {"records": [{"email": "[email protected]", "status": "active"}], "affectedCount": 1}}}
(1 row)

select graphql.resolve($$
mutation newAccount($acc: AccountInsertInput!) {
insertIntoAccountCollection(objects: [$acc]) {
affectedCount
records {
id
email
}
}
}
$$,
variables := '{"acc": {"email": "[email protected]"}}'::jsonb
);
resolve
-----------------------------------------------------------------------------------------------------------------
{"data": {"insertIntoAccountCollection": {"records": [{"id": 8, "email": "[email protected]"}], "affectedCount": 1}}}
(1 row)

select graphql.resolve($$
mutation newAccounts($acc: [AccountInsertInput!]!) {
insertIntoAccountCollection(objects: $accs) {
affectedCount
records {
id
email
}
}
}
$$,
variables := '{"accs": [{"email": "[email protected]"}]}'::jsonb
);
resolve
-----------------------------------------------------------------------------------------------------------------
{"data": {"insertIntoAccountCollection": {"records": [{"id": 9, "email": "[email protected]"}], "affectedCount": 1}}}
(1 row)

-- Single object coerces to a list
select graphql.resolve($$
mutation {
insertIntoBlogCollection(objects: {ownerId: 1}) {
affectedCount
}
}
$$);
resolve
--------------------------------------------------------------
{"data": {"insertIntoBlogCollection": {"affectedCount": 1}}}
(1 row)

/*
Errors
*/
-- Field does not exist
select graphql.resolve($$
mutation createAccount($acc: AccountInsertInput) {
insertIntoAccountCollection(objects: [$acc]) {
affectedCount
records {
id
email
}
}
}
$$,
variables := '{"acc": {"doesNotExist": "other"}}'::jsonb
);
resolve
---------------------------------------------------------------------------------------------------------------------
{"data": null, "errors": [{"message": "Input for type AccountInsertInput contains extra keys [\"doesNotExist\"]"}]}
(1 row)

-- Wrong input type (list of string, not list of object)
select graphql.resolve($$
mutation {
insertIntoBlogCollection(objects: ["not an object"]) {
affectedCount
}
}
$$);
resolve
-----------------------------------------------------------------------------------
{"data": null, "errors": [{"message": "Invalid input for BlogInsertInput type"}]}
(1 row)

-- objects argument is missing
select graphql.resolve($$
mutation {
insertIntoBlogCollection {
affectedCount
}
}
$$);
resolve
---------------------------------------------------------------------------
{"data": null, "errors": [{"message": "Invalid input for NonNull type"}]}
(1 row)

-- Empty call
select graphql.resolve($$
mutation {
insertIntoBlogCollection(objects: []) {
affectedCount
}
}
$$);
resolve
--------------------------------------------------------------------------------------------
{"data": null, "errors": [{"message": "At least one record must be provided to objects"}]}
(1 row)

rollback;
Loading
Loading