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
64 changes: 64 additions & 0 deletions dbquery/pings/postgresql/README.md
Original file line number Diff line number Diff line change
@@ -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 `<<xxx>>` 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://<<host>>/<<database>>?user=<<user>>&password=<<password>>
```

### `.env` contents

```
STEPZEN_PG_DB_URI=postgresql://<<host>>/<<database>>?user=<<user>>&password=<<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"
}
}
}
```
4 changes: 4 additions & 0 deletions dbquery/pings/postgresql/config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
configurationset:
- configuration:
name: pgdb
uri: STEPZEN_PG_DB_URI
15 changes: 15 additions & 0 deletions dbquery/pings/postgresql/index.graphql
Original file line number Diff line number Diff line change
@@ -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
}
3 changes: 3 additions & 0 deletions dbquery/pings/postgresql/stepzen.config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"endpoint": "dbping/postgresql"
}
12 changes: 12 additions & 0 deletions dbquery/pings/postgresql/tests/Test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
const {
deployAndRun,
authTypes,
getTestDescription,
} = require("../../../../tests/gqltest.js");

testDescription = getTestDescription("snippets", __dirname);

describe(testDescription, function () {
const tests = [];
return deployAndRun(__dirname, tests);
});