Skip to content

Commit 44b77b8

Browse files
authored
Merge branch 'main' into jwt-claim-pagination
2 parents 471562f + 2af549a commit 44b77b8

File tree

73 files changed

+1228
-918
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

73 files changed

+1228
-918
lines changed

dbquery/pagination/operations.graphql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# Page through customers from a database connection based pagination
2-
query Customers($first: Int!, $after: String = "") {
2+
query Customers($first: Int!, $after: String = "") {
33
customers(first: $first, after: $after) {
44
edges {
55
node {

dbquery/pagination/tests/Test.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ const fs = require("fs");
22
const path = require("node:path");
33
const {
44
deployAndRun,
5-
authTypes,
5+
stepzen,
66
getTestDescription,
77
} = require("../../../tests/gqltest.js");
88

@@ -44,7 +44,6 @@ describe(testDescription, function () {
4444
}
4545
}
4646
},
47-
authType: authTypes.adminKey,
4847
},
4948
{
5049
label: "next set of results",
@@ -76,8 +75,7 @@ describe(testDescription, function () {
7675
}
7776
}
7877
},
79-
authType: authTypes.adminKey,
8078
},
8179
];
82-
return deployAndRun(__dirname, tests);
80+
return deployAndRun(__dirname, tests, stepzen.admin);
8381
});

dbquery/pings/postgresql/README.md

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
# Ping PostgreSQL
2+
3+
Simple schema that when deployed provides an easy way to check that a
4+
PostgreSQL database can be connected to from a GraphQL endpoint.
5+
6+
## Setup
7+
8+
Either set an environment variable or an `.env` file containing the URI of the PostgreSQL instance.
9+
10+
Replace `<<xxx>>` values with the correct connection information.
11+
12+
If a port number is required then add it to the host as `:1234`.
13+
14+
If the password contains special characters then must be URL escaped.
15+
16+
### Environment variable
17+
```
18+
export STEPZEN_PG_DB_URI=postgresql://<<host>>/<<database>>?user=<<user>>&password=<<password>>
19+
```
20+
21+
### `.env` contents
22+
23+
```
24+
STEPZEN_PG_DB_URI=postgresql://<<host>>/<<database>>?user=<<user>>&password=<<password>>
25+
```
26+
27+
## Deploy
28+
29+
```
30+
stepzen deploy
31+
```
32+
33+
## Test
34+
35+
```
36+
stepzen request '{ping{status}}'
37+
```
38+
39+
## Example
40+
41+
```
42+
>stepzen deploy
43+
Deploying dbping/postgresql to StepZen... done in 443ms 🚀
44+
✓ 🔐 https://danville.us-east-a.ibm.stepzen.net/dbping/postgresql/__graphql
45+
✓ 🔐 wss://danville.us-east-a.ibm.stepzen.net/stepzen-subscriptions/dbping/postgresql/__graphql (subscriptions)
46+
47+
You can test your hosted API with curl:
48+
49+
curl https://danville.us-east-a.ibm.stepzen.net/dbping/postgresql/__graphql \
50+
--header "Authorization: Apikey $(stepzen whoami --apikey)" \
51+
--header "Content-Type: application/json" \
52+
--data-raw '{
53+
"query": "query SampleQuery { __schema { description queryType { fields {name} } } }"
54+
}'
55+
56+
stepzen request '{ping{status}}'
57+
{
58+
"data": {
59+
"ping": {
60+
"status": "ok"
61+
}
62+
}
63+
}
64+
```
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
configurationset:
2+
- configuration:
3+
name: pgdb
4+
uri: STEPZEN_PG_DB_URI
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
type Query {
2+
"""
3+
Pings the configured database by running a SQL statement
4+
that does not access any user tables or schema.
5+
"""
6+
ping: Ping
7+
@dbquery(
8+
type: "postgresql"
9+
query: "SELECT 'ok' AS status"
10+
configuration: "pgdb"
11+
)
12+
}
13+
type Ping {
14+
status: String
15+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"endpoint": "dbping/postgresql"
3+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
const {
2+
deployAndRun,
3+
getTestDescription,
4+
} = require("../../../../tests/gqltest.js");
5+
6+
testDescription = getTestDescription("snippets", __dirname);
7+
8+
describe(testDescription, function () {
9+
const tests = [];
10+
return deployAndRun(__dirname, tests);
11+
});

executable/persisted/README.md

Lines changed: 135 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,135 @@
1+
# Persisted Documents
2+
3+
GraphQL _executable documents_ containing at least one operation definition
4+
and optional fragment defintions can be persisted with a schema.
5+
6+
## Overview
7+
8+
The optional `executables` argument of `@sdl` takes a list of input document files
9+
that are GraphQL _executable documents_.
10+
11+
```
12+
@sdl(
13+
files: []
14+
executables: [{ document: "operations.graphql", persist: true }]
15+
)
16+
```
17+
18+
When a schema is deployed the _executable documents_ must validate successfully
19+
against the schema.
20+
21+
By itself this can be used to validate applications' use
22+
of a GraphQL endpoint remain valid when the schema changes.
23+
This requires that the application loads GraphQL requests from
24+
files containing executable documents that are declared in the schema.
25+
26+
In addition any _executable document_ in the schema that is marked with `persist: true`
27+
is loaded as a _persisted document_.
28+
29+
A client uses a _persisted document_ by specifying its document identifier
30+
(based upon a SHA256 hash) in a request instead of the content of the _executable document_.
31+
32+
For example instead of this POST body for a request:
33+
34+
```
35+
{
36+
"query": "{__typname}"
37+
}
38+
```
39+
40+
a request can use this:
41+
42+
```
43+
{
44+
"documentId": "sha256:ecf4edb46db40b5132295c0291d62fb65d6759a9eedfa4d5d612dd5ec54a6b38"
45+
}
46+
```
47+
48+
if an _executable document_ was declared in the schema with the matching SHA256 hash.
49+
50+
The request parameters `operationName` and `variables` can be used as required with `documentId`.
51+
52+
## Benefits
53+
54+
Use of persisted documents typically saves network bandwidth as for real application requests
55+
the hash is smaller than the body of the _executable document_.
56+
57+
In addition query requests can use HTTP GET while maintaining a reasonable sized URL
58+
that improves caching of URL requests. For example the above request can be a coded as an HTTP GET:
59+
60+
```
61+
https://london.us-east-a.ibm.stepzen.net/api/customer/graphql?documentId=sha256%3Aecf4edb46db40b5132295c0291d62fb65d6759a9eedfa4d5d612dd5ec54a6b38
62+
```
63+
64+
## Executable Documents
65+
66+
A good practice is to ensure that a CI/CD process ensures that _executable documents_ declared as
67+
part of the schema using `@sdl(executables:)` are formatted consistently, using tooling such as `prettier`.
68+
69+
For example the simple _executable document_ shown above `{__typename}` stored in a document file
70+
and formatted will have contents (including a newline at the end):
71+
72+
```
73+
{
74+
__typename
75+
}
76+
```
77+
78+
and thus a document identifier of `sha256:8d8f7365e9e86fa8e3313fcaf2131b801eafe9549de22373089cf27511858b39`.
79+
80+
Clients can obtain the SHA256 hash for a document identifer using any standard mechanism for calculating hashes,
81+
for example on Linux/Unix systems this command can be used:
82+
83+
```
84+
shasum -a 256 operations.graphql
85+
```
86+
87+
When _executable documents_ are persisted using `@sdl(executables:)` the schema calculates the document identifiers automatically.
88+
89+
## Example
90+
91+
This example uses a simple mocked schema with a `Customer` type and a single `Query` field `customer`.
92+
93+
`operations.graphql` contains three GraphQL query operations `Customer`, `CustomerEmail` and `CustomerName`
94+
each with a different selection against `Query.customer`.
95+
96+
A client can execute them using these request parameters, shown as JavaScript:
97+
98+
```
99+
{
100+
documentId: "sha256:9d50d8e35b5882139e836a126f5d6d5a28cf41c5efd80a6e67f920d284b5f6d0",
101+
operationName: "Customer",
102+
variables: {
103+
id: 1789,
104+
},
105+
}
106+
```
107+
108+
```
109+
{
110+
documentId: "sha256:9d50d8e35b5882139e836a126f5d6d5a28cf41c5efd80a6e67f920d284b5f6d0",
111+
operationName: "CustomerEmail",
112+
variables: {
113+
id: 2845,
114+
},
115+
}
116+
```
117+
118+
```
119+
{
120+
documentId: "sha256:9d50d8e35b5882139e836a126f5d6d5a28cf41c5efd80a6e67f920d284b5f6d0",
121+
operationName: "CustomerName",
122+
variables: {
123+
id: 3651,
124+
},
125+
}
126+
```
127+
128+
For example use `curl` and HTTP `GET` as follows:
129+
130+
```
131+
curl \
132+
--header "Authorization: Apikey $(stepzen whoami --apikey)" \
133+
--header "Content-Type: application/json" \
134+
'https://london.us-east-a.ibm.stepzen.net/api/miscellaneous/graphql?documentId=sha256:9d50d8e35b5882139e836a126f5d6d5a28cf41c5efd80a6e67f920d284b5f6d0&operationName=Customer&variables=%7B%22id%22%3A%201789%7D'
135+
```

executable/persisted/index.graphql

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
schema
2+
@sdl(
3+
files: []
4+
# executables defines a list of GraphQL executable documents that
5+
# are validated against the schema when deployed.
6+
# If an executable document is marked as persist: true
7+
# then it becomes a persisted document with the document identifier
8+
# being tha SHA 256 hash of the document file.
9+
executables: [{ document: "operations.graphql", persist: true }]
10+
) {
11+
query: Query
12+
}
13+
14+
type Query {
15+
customer(id: ID!): Customer
16+
}
17+
type Customer @mock {
18+
id: ID!
19+
name: String! @mockfn(name: "LastName")
20+
email: String @mockfn(name: "Email")
21+
phone: String @mockfn(name: "Phone")
22+
address: Address
23+
}
24+
type Address {
25+
city: String @mockfn(name: "City")
26+
zip: String @mockfn(name: "Zip")
27+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
query Customer($id: ID!) {
2+
customer(id: $id) {
3+
id
4+
name
5+
email
6+
phone
7+
address {
8+
city
9+
zip
10+
}
11+
}
12+
}
13+
14+
query CustomerName($id: ID!) {
15+
customer(id: $id) {
16+
name
17+
}
18+
}
19+
20+
query CustomerEmail($id: ID!) {
21+
customer(id: $id) {
22+
email
23+
}
24+
}

0 commit comments

Comments
 (0)