Skip to content

Commit

Permalink
Backport V5 test system to V4 (#794)
Browse files Browse the repository at this point in the history
Co-authored-by: Jem Gillam <6413628+jemgillam@users.noreply.github.com>
  • Loading branch information
benjie and jemgillam authored Aug 26, 2022
1 parent 5b18a12 commit 06dddf8
Show file tree
Hide file tree
Showing 249 changed files with 60,287 additions and 45 deletions.
484 changes: 484 additions & 0 deletions packages/postgraphile-core/__tests__/helpers-v5.js

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -44,25 +44,33 @@ beforeAll(() => {
enumTables,
geometry,
] = await Promise.all([
// gqlSchema
createPostGraphileSchema(pgClient, ["a", "b", "c"]),
// dSchema
createPostGraphileSchema(pgClient, ["d"]),
// inheritenceSchema
createPostGraphileSchema(pgClient, ["inheritence"]),
// pg11Schema
serverVersionNum >= 110000
? createPostGraphileSchema(pgClient, ["pg11"])
: null,
// useCustomNetworkScalarsSchema
createPostGraphileSchema(pgClient, ["network_types"], {
graphileBuildOptions: {
pgUseCustomNetworkScalars: true,
},
}),
// pg11UseCustomNetworkScalarsSchema
serverVersionNum >= 110000
? createPostGraphileSchema(pgClient, ["pg11"], {
graphileBuildOptions: {
pgUseCustomNetworkScalars: true,
},
})
: null,
// enumTables
createPostGraphileSchema(pgClient, ["enum_tables"]),
// geometry
createPostGraphileSchema(pgClient, ["geometry"], {
graphileBuildOptions: {
pgGeometricTypes: true,
Expand Down Expand Up @@ -90,7 +98,7 @@ beforeAll(() => {
// Execute all of the mutations in parallel. We will not wait for them to
// resolve or reject. The tests will do that.
//
// All of our mutations get there own Postgres client instance. Queries share
// All of our mutations get their own Postgres client instance. Queries share
// a client instance.
mutationResults = mutationFileNames.map(async fileName => {
// Wait for the schema to resolve. We need the schema to be introspected
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
const { graphql } = require("graphql");
const { withPgClient } = require("../helpers");
const { createPostGraphileSchema } = require("../..");
const { readdirSync, readFile: rawReadFile } = require("fs");

let schema;

Expand All @@ -11,22 +12,27 @@ beforeAll(async () => {
);
});

function readFile(filename, encoding) {
return new Promise((resolve, reject) => {
rawReadFile(filename, encoding, (err, res) => {
if (err) reject(err);
else resolve(res);
});
});
}
const kitchenSinkData = () =>
readFile(`${__dirname}/../kitchen-sink-data.sql`, "utf8");

test("numeric range", () =>
withPgClient(async pgClient => {
const {
rows: [row],
} = await pgClient.query(
"insert into ranges.range_test (num) values (numrange($1, $2)) returning *",
["-1234567890123456789.123456789012", "1111111111111111111.111111111111"]
);
await pgClient.query(await kitchenSinkData());
const result = await graphql(
schema,
"query ($id: Int!) {rangeTestById(id:$id) {num{start {value inclusive} end { value inclusive } }}}",
"{rangeTestById(id: 934) {num{start {value inclusive} end { value inclusive } }}}",
null,
{
pgClient: pgClient,
},
{ id: row.id }
}
);
expect(result.errors).toBeFalsy();
expect(result.data.rangeTestById.num).toEqual({
Expand All @@ -43,20 +49,14 @@ test("numeric range", () =>

test("bigint range", () =>
withPgClient(async pgClient => {
const {
rows: [row],
} = await pgClient.query(
"insert into ranges.range_test (int8) values (int8range($1, $2)) returning *",
["-98765432109876543", "22222222222222222"]
);
await pgClient.query(await kitchenSinkData());
const result = await graphql(
schema,
"query ($id: Int!) {rangeTestById(id:$id) {int8{start {value inclusive} end { value inclusive } }}}",
"{rangeTestById(id:934) {int8{start {value inclusive} end { value inclusive } }}}",
null,
{
pgClient: pgClient,
},
{ id: row.id }
}
);
expect(result.errors).toBeFalsy();
expect(result.data.rangeTestById.int8).toEqual({
Expand All @@ -73,20 +73,14 @@ test("bigint range", () =>

test("ts range", () =>
withPgClient(async pgClient => {
const {
rows: [row],
} = await pgClient.query(
"insert into ranges.range_test (ts) values (tsrange($1::timestamp, null)) returning *",
["2019-01-10 21:45:56.356022"]
);
await pgClient.query(await kitchenSinkData());
const result = await graphql(
schema,
"query ($id: Int!) {rangeTestById(id:$id) {ts{start {value inclusive} }}}",
"{rangeTestById(id:934) {ts{start {value inclusive} }}}",
null,
{
pgClient: pgClient,
},
{ id: row.id }
}
);
expect(result.errors).toBeFalsy();
expect(result.data.rangeTestById.ts).toEqual({
Expand All @@ -99,20 +93,14 @@ test("ts range", () =>

test("tstz range", () =>
withPgClient(async pgClient => {
const {
rows: [row],
} = await pgClient.query(
"insert into ranges.range_test (tstz) values (tstzrange($1::timestamptz, null)) returning *",
["2019-01-10 21:45:56.356022+00"]
);
await pgClient.query(await kitchenSinkData());
const result = await graphql(
schema,
"query ($id: Int!) {rangeTestById(id:$id) {tstz{start {value inclusive} }}}",
"{rangeTestById(id:934) {tstz{start {value inclusive} }}}",
null,
{
pgClient: pgClient,
},
{ id: row.id }
}
);
expect(result.errors).toBeFalsy();
expect(result.data.rangeTestById.tstz).toEqual({
Expand Down
12 changes: 12 additions & 0 deletions packages/postgraphile-core/__tests__/integration/queries.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ beforeAll(() => {
enumTables,
geometry,
] = await Promise.all([
// normal
createPostGraphileSchema(pgClient, ["a", "b", "c"], {
subscriptions: true,
appendPlugins: [
Expand All @@ -79,10 +80,12 @@ beforeAll(() => {
}),
],
}),
//classicIds
createPostGraphileSchema(pgClient, ["a", "b", "c"], {
subscriptions: true,
classicIds: true,
}),
//dynamicJson
createPostGraphileSchema(pgClient, ["a", "b", "c"], {
subscriptions: true,
dynamicJson: true,
Expand All @@ -93,29 +96,36 @@ beforeAll(() => {
pgColumnFilter: attr => attr.name !== "headline",
setofFunctionsContainNulls: false,
}),
// viewUniqueKey
createPostGraphileSchema(pgClient, ["a", "b", "c"], {
subscriptions: true,
viewUniqueKey: "testviewid",
setofFunctionsContainNulls: true,
}),
// d schema
createPostGraphileSchema(pgClient, ["d"], {}),
//simpleCollections
createPostGraphileSchema(pgClient, ["a", "b", "c"], {
subscriptions: true,
simpleCollections: "both",
}),
// orderByNullsLast
createPostGraphileSchema(pgClient, ["a"], {
subscriptions: true,
graphileBuildOptions: {
orderByNullsLast: true,
},
}),
// smartCommentRelations
createPostGraphileSchema(pgClient, ["smart_comment_relations"], {}),
createPostGraphileSchema(pgClient, ["large_bigint"], {}),
// network_types
createPostGraphileSchema(pgClient, ["network_types"], {
graphileBuildOptions: {
pgUseCustomNetworkScalars: true,
},
}),
// pg11
serverVersionNum >= 110000
? createPostGraphileSchema(pgClient, ["pg11"], {
graphileBuildOptions: {
Expand All @@ -127,9 +137,11 @@ beforeAll(() => {
subscriptions: true,
appendPlugins: [ToyCategoriesPlugin],
}),
//enum tables
createPostGraphileSchema(pgClient, ["enum_tables"], {
subscriptions: true,
}),
//geometry
createPostGraphileSchema(pgClient, ["geometry"], {
subscriptions: true,
graphileBuildOptions: {
Expand Down
Loading

0 comments on commit 06dddf8

Please sign in to comment.