Skip to content

Commit 1870de1

Browse files
committed
chore: cleanup
1 parent 13494c2 commit 1870de1

File tree

2 files changed

+53
-3
lines changed

2 files changed

+53
-3
lines changed

executable/persisted/README.md

Lines changed: 49 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ In addition query requests can use HTTP GET while maintaining a reasonable sized
5858
that improves caching of URL requests. For example the above request can be a coded as an HTTP GET:
5959

6060
```
61-
https://london.us-east-a.ibm.stepzen.net/api/customer/graphql?documentId=sha256:ecf4edb46db40b5132295c0291d62fb65d6759a9eedfa4d5d612dd5ec54a6b38
61+
https://london.us-east-a.ibm.stepzen.net/api/customer/graphql?documentId=sha256%3Aecf4edb46db40b5132295c0291d62fb65d6759a9eedfa4d5d612dd5ec54a6b38
6262
```
6363

6464
## Executable Documents
@@ -85,3 +85,51 @@ shasum -a 256 operations.graphql
8585
```
8686

8787
When _executable document_ 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+
```

tests/gqltest.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ function deployEndpoint(endpoint, dirname) {
4545
// as a test returning the response.
4646
// The test will fail if the request does not
4747
// have status 200 or has any GraphQL errors.
48-
function runGqlOk(authType, endpoint, query, variables, operationName) {
48+
function runGqlOk(authType, endpoint, documentId, query, variables, operationName) {
4949
switch (authType) {
5050
case authTypes.adminKey:
5151
authValue = adminKey;
@@ -66,6 +66,7 @@ function runGqlOk(authType, endpoint, query, variables, operationName) {
6666
Authorization: authValue,
6767
},
6868
body: JSON.stringify({
69+
documentId: documentId,
6970
query: query,
7071
variables: variables,
7172
operationName: operationName,
@@ -102,12 +103,13 @@ function deployAndRun(dirname, tests) {
102103
});
103104

104105
tests.forEach(
105-
({ label, query, variables, operationName, expected, authType }) => {
106+
({ label, documentId, query, variables, operationName, expected, authType }) => {
106107
it(label, function () {
107108
this.timeout(4000); // Occasional requests take > 2s
108109
return runGqlOk(
109110
authType,
110111
endpoint,
112+
documentId,
111113
query,
112114
variables,
113115
operationName

0 commit comments

Comments
 (0)