From 987dc2535064c64c1e4323b0e56ab55c5eefc9e0 Mon Sep 17 00:00:00 2001 From: Dan Debrunner Date: Wed, 28 Aug 2024 10:24:57 -0400 Subject: [PATCH 1/3] chore: postgresql ping schema --- dbquery/pings/postgresql/README.md | 64 ++++++++++++++++++++ dbquery/pings/postgresql/config.yaml | 4 ++ dbquery/pings/postgresql/index.graphql | 15 +++++ dbquery/pings/postgresql/stepzen.config.json | 3 + 4 files changed, 86 insertions(+) create mode 100644 dbquery/pings/postgresql/README.md create mode 100644 dbquery/pings/postgresql/config.yaml create mode 100644 dbquery/pings/postgresql/index.graphql create mode 100644 dbquery/pings/postgresql/stepzen.config.json diff --git a/dbquery/pings/postgresql/README.md b/dbquery/pings/postgresql/README.md new file mode 100644 index 0000000..9c0f286 --- /dev/null +++ b/dbquery/pings/postgresql/README.md @@ -0,0 +1,64 @@ +# Ping PostgreSQL + +Simple schema that when deployed provides an easy way to check that a +PostgreSQL database can be connected to from a GraphQL endpoint. + +## Setup + +Either set an environment variable or an `.env` file containing the URI of the PostgreSQL instance. + +Replace `<>` values with the correct connection information. + +If a port number is required then add it to the host as `:1234`. + +If the password contains special characters then must be URL escaped. + +### Environment variable +``` +export STEPZEN_PG_DB_URI=postgresql://<>/<>?user=<>&password=<> +``` + +### `.env` contents + +``` +STEPZEN_PG_DB_URI=postgresql://<>/<>?user=<>&password=<> +``` + +## Deploy + +``` +stepzen deploy +``` + +## Test + +``` +stepzen request '{ping{status}}' +``` + +## Example + +``` +>stepzen deploy +Deploying dbping/postgresql to StepZen... done in 443ms 🚀 + ✓ 🔐 https://danville.us-east-a.ibm.stepzen.net/dbping/postgresql/__graphql + ✓ 🔐 wss://danville.us-east-a.ibm.stepzen.net/stepzen-subscriptions/dbping/postgresql/__graphql (subscriptions) + +You can test your hosted API with curl: + +curl https://danville.us-east-a.ibm.stepzen.net/dbping/postgresql/__graphql \ + --header "Authorization: Apikey $(stepzen whoami --apikey)" \ + --header "Content-Type: application/json" \ + --data-raw '{ + "query": "query SampleQuery { __schema { description queryType { fields {name} } } }" + }' + +stepzen request '{ping{status}}' +{ + "data": { + "ping": { + "status": "ok" + } + } +} +``` \ No newline at end of file diff --git a/dbquery/pings/postgresql/config.yaml b/dbquery/pings/postgresql/config.yaml new file mode 100644 index 0000000..90280a1 --- /dev/null +++ b/dbquery/pings/postgresql/config.yaml @@ -0,0 +1,4 @@ +configurationset: + - configuration: + name: pgdb + uri: STEPZEN_PG_DB_URI diff --git a/dbquery/pings/postgresql/index.graphql b/dbquery/pings/postgresql/index.graphql new file mode 100644 index 0000000..78d967a --- /dev/null +++ b/dbquery/pings/postgresql/index.graphql @@ -0,0 +1,15 @@ +type Query { + """ + Pings the configured database by running a SQL statement + that does not access any user tables or schema. + """ + ping: Ping + @dbquery( + type: "postgresql" + query: "SELECT 'ok' AS status" + configuration: "pgdb" + ) +} +type Ping { + status: String +} diff --git a/dbquery/pings/postgresql/stepzen.config.json b/dbquery/pings/postgresql/stepzen.config.json new file mode 100644 index 0000000..7a49002 --- /dev/null +++ b/dbquery/pings/postgresql/stepzen.config.json @@ -0,0 +1,3 @@ +{ + "endpoint": "dbping/postgresql" +} From 96a9d5e2e750c06caba95ed465defc7a7aec3a33 Mon Sep 17 00:00:00 2001 From: Dan Debrunner Date: Wed, 28 Aug 2024 10:58:03 -0400 Subject: [PATCH 2/3] chore: fix path --- dbquery/pings/postgresql/tests/Test.js | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 dbquery/pings/postgresql/tests/Test.js diff --git a/dbquery/pings/postgresql/tests/Test.js b/dbquery/pings/postgresql/tests/Test.js new file mode 100644 index 0000000..69492ed --- /dev/null +++ b/dbquery/pings/postgresql/tests/Test.js @@ -0,0 +1,13 @@ +const { + deployAndRun, + authTypes, + getTestDescription, +} = require("../../../../tests/gqltest.js"); + +testDescription = getTestDescription("snippets", __dirname); + +describe(testDescription, function () { + const tests = [ + ] + return deployAndRun(__dirname, tests); +}); \ No newline at end of file From 6cf1775b75967bb574cd50b4f59c92a984df5df4 Mon Sep 17 00:00:00 2001 From: Dan Debrunner Date: Wed, 28 Aug 2024 11:00:13 -0400 Subject: [PATCH 3/3] chore: prettier --- dbquery/pings/postgresql/tests/Test.js | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/dbquery/pings/postgresql/tests/Test.js b/dbquery/pings/postgresql/tests/Test.js index 69492ed..c19498d 100644 --- a/dbquery/pings/postgresql/tests/Test.js +++ b/dbquery/pings/postgresql/tests/Test.js @@ -7,7 +7,6 @@ const { testDescription = getTestDescription("snippets", __dirname); describe(testDescription, function () { - const tests = [ - ] + const tests = []; return deployAndRun(__dirname, tests); -}); \ No newline at end of file +});