Skip to content

Commit cf2ff99

Browse files
authored
Merge branch 'main' into mkall-field-access
2 parents 84cda1e + 8908a18 commit cf2ff99

File tree

78 files changed

+968
-818
lines changed

Some content is hidden

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

78 files changed

+968
-818
lines changed

README.md

Lines changed: 25 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -27,93 +27,49 @@
2727
- [Explore the docs](https://stepzen.com/docs)
2828
- [View Demo](https://stepzen.com/developers/videos/graph-of-graphs)
2929
- [Report Bug](https://github.com/stepzen-dev/snippets/issues)
30-
- [Request Snippet](https://github.com/stepzen-dev/issues)
30+
- [Request Snippet](https://github.com/stepzen-dev/snippets/issues)
3131
- [Join our Discord Server](https://discord.com/invite/9k2VdPn2FR)
3232
</p>
3333
</div>
3434

35-
<!-- TABLE OF CONTENTS -->
36-
<details>
37-
<summary>Table of Contents</summary>
38-
<ol>
39-
<li>
40-
<a href="#about-the-project">About The Project</a>
41-
</li>
42-
<li><a href="#transforms">`@transforms`</a></li>
43-
<li><a href="#sequence">`@sequence`</a></li>
44-
<li><a href="#protection">protection</a></li>
45-
<li><a href="#rest-calls-and-responses">`@rest` calls and responses</a></li>
46-
47-
</ol>
48-
</details>
49-
5035
## About the project
5136

52-
This repo contains `.graphql` (and in some case, `config.yaml` files) for various "self-contained" example code for doing operations in StepZen.
37+
Code snippets that demonstrate use of custom directives and other techniques in
38+
IBM API Connect Essentials (StepZen).
5339

5440
## Getting Started
5541

56-
[Install](https://stepzen.com/docs/quick-start/install-and-setup) the StepZen command line interface.
57-
58-
To run these examples,
59-
60-
- `git clone` this repo
61-
- Change to the right working directory.
62-
- run `stepzen start`
63-
64-
## transforms
65-
66-
For more on what `transforms` is and how it operates within the custom `@rest` directive, [see our documentation](https://stepzen.com/docs/custom-graphql-directives/directives#transforms).
67-
68-
These are available in `/transforms`:
69-
70-
- `/filter` shows how the response of a REST API can be filtered
71-
- `/combineintostring` shows how a new field in the return type can be created by concatenating some other fields (like address parts into one address)
72-
- `/jsonobjectToJsonarray` shows how an array of data (say coords) can be converted into an object, `{"lat":, "lon",..}` so that it can be fed into some other system that requires data to be expressed that way
73-
- `/jsonobjectToJsonarray` shows how an object (typically where each key is an id of a record) can be converted into an array (e.g., `{"1":{"name": "john"}, "2": "jane"}` can be converted to `[{"id":"1", "name": "john"}, {"id":"2", name: "jane"}]`), so that it can then behave well for GraphQL processing.
74-
75-
## @sequence
76-
77-
View the StepZen [documentation](https://stepzen.com/docs/custom-graphql-directives/directives#-sequence) on the custom directive `@sequence`.
78-
79-
These are available in `/sequence`:
80-
81-
- `/arguments` shows how query arguments get passed down a sequence
82-
- `/forLoops` shows how sequence acts as a nested for loop
83-
- `/transformsInMaterializer` shows how connecting two subgraphs can invoke transformations in between. For example, the `city` of a customer can be fed into a `weather` that takes `lat,lon` by calling some geocoding in the sequence
84-
- `/useOfJSON` shows how, in long sequences, a new type does not have to created for every step--treat everything as JSON up to the last step, and your type system stays clean.
85-
86-
## @dbquery
87-
88-
View the documentation for the [`@dbquery` custom directive](https://www.ibm.com/docs/en/api-connect/ace/saas?topic=directives-directive-dbquery) in the documentation.
89-
90-
Uses a database filled with mock data.
91-
92-
- `/pagination` shows how to implement connection model pagination for a database.
93-
94-
## protection
42+
Sign up for a free API Connect Essentials SaaS plan: https://www.ibm.com/account/reg/us-en/signup?formid=urx-52542
9543

96-
For more information on protecting your API, [see our documentation](https://stepzen.com/docs/access-control).
44+
Read: [understanding API Connect Essentials (StepZen)](https://www.ibm.com/docs/en/api-connect/ace/saas?topic=understanding-api-connect-essentials)
9745

98-
In `/protection`, you will find several subdirectories. Each contains a `.graphql` file, and `index.graphql` file and a `config.yaml` settings (which enables you to get extremely granular (or coarse) with protecting who can call what query/mutation).
46+
[Install](https://www.ibm.com/docs/en/api-connect/ace/saas?topic=setting-up-your-environment#set-up-env__title__3) the StepZen command line interface.
9947

100-
- `/makeAllPublic` shows how you can easily make all queries public.
101-
- `/makeSomePublic` shows how you can make some public, and some private (which can still be accessed using your `admin` or `service` keys)
48+
Documentation: https://www.ibm.com/docs/en/api-connect/ace/saas
10249

103-
## @rest calls and responses
50+
## Snippets
10451

105-
Where possible, we use [httpbingo.org](https://httpbingo.org) as our REST endpoint, since it allows us to mimic lots of REST capabilities.
52+
The snippets are generally broken up into functional areas, with each folder covering a specific topic:
10653

107-
- `/restWithParameters` shows how GraphQL query arguments are automatically added to the REST call--there is nothing for you to do!
108-
- `/restWithConfigYaml` shows how REST query parameters can also be fetched from `config.yaml`--this allows you to keep your SDL code separate from your secrets.
109-
- `/postbody` shows how a POST body can be automatically filled with query arguments when the `Content-Type:application/x-www-form-urlencoded`. This is the easiest way to send postbodies down the REST API
110-
- `/morecomplexpost` shows how a POST body can be filled with query arguments using `{{.Get \"name-of-query-argument\"}}` when the `Content-Type:application/x-www-form-urlencoded`.
54+
### Custom Directives
11155

112-
## union types
56+
- [@dbquery](dbquery/README.md) - Use `@dbquery` for connecting to databases, including pagination and filtering.
57+
- [@materializer](materializer) - Use of `@materializer` to extend types by linking disparate backends into a single unified view.
58+
- @rest - Connects to REST APIs
59+
- [rest](rest/README.md) - Use of `@rest` for connecting to REST endpoints, including pagination.
60+
- [transforms](transforms/README.md) - How to transform REST API responses to match GraphQL types with `@rest`.
61+
- [@sequence](sequence/README.md) - Use of `@sequence` to resolve a field from multiple field resolutions, such as multiple backend calls.
62+
- @sdl
63+
- [executable](executable) - How GraphQL _executable documents_ can be registered and used with a schema or endpoint.
64+
- @supplies
65+
- [routing](routing)
11366

114-
Union types are valuable when you have a field that can return one of several types.
67+
### General topics
11568

116-
- `/errorsAsData` shows how to implement the "errors as data" pattern. This is useful when you want to return a field that can return either a value or an error.
69+
- [pocs](pocs) - Techniques that can be used during development of proof of concepts with StepZen.
70+
- [protection](protection/README.md) - How to protect or expose GraphQL endpoints including field based access rules.
71+
- [reshape](reshape/README.md) - How to reshape GraphQL schema elements.
72+
- [unions](unions/README.md) - Uses of the GraphQL `union` type.
11773

11874
<!-- MARKDOWN LINKS & IMAGES -->
11975
<!-- https://www.markdownguide.org/basic-syntax/#reference-style-links -->

dbquery/README.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# @dbquery
2+
3+
The custom directive `@dbquery` allows easy declarative inclusion of a database backend in a GraphQL schema.
4+
5+
GraphQL pagination and filtering are easily supported.
6+
7+
View the documentation for the [`@dbquery` custom directive](https://www.ibm.com/docs/en/api-connect/ace/saas?topic=directives-directive-dbquery) in the documentation.
8+
9+
Uses a database filled with mock data.
10+
11+
- [pagination](pagination) shows how to implement connection model pagination for a database.
12+
- [pings](pings) has snippets that can be deployed to see if connectivity to a database is setup correctly.

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/tests/Test.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
const {
22
deployAndRun,
3-
authTypes,
43
getTestDescription,
54
} = require("../../../../tests/gqltest.js");
65

executable/persisted/tests/Test.js

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ const path = require("node:path");
33

44
const {
55
deployAndRun,
6-
authTypes,
6+
stepzen,
77
getTestDescription,
88
} = require("../../../tests/gqltest.js");
99

@@ -27,7 +27,6 @@ describe(testDescription, function () {
2727
name: "Tromp",
2828
},
2929
},
30-
authType: authTypes.adminKey,
3130
},
3231
{
3332
label: "CustomerName",
@@ -42,7 +41,6 @@ describe(testDescription, function () {
4241
4342
},
4443
},
45-
authType: authTypes.adminKey,
4644
},
4745
{
4846
label: "Customer",
@@ -64,8 +62,7 @@ describe(testDescription, function () {
6462
},
6563
},
6664
},
67-
authType: authTypes.adminKey,
6865
},
6966
];
70-
return deployAndRun(__dirname, tests);
67+
return deployAndRun(__dirname, tests,stepzen.admin);
7168
});
Lines changed: 35 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
# See preamble in README.md
22

33
type Document {
4-
docId: String
5-
content(id: String!): Content
6-
@materializer(query: "content", arguments:[{name: "id" argument:"id"}])
7-
author: Author
8-
lastUpdate: Date
4+
docId: String
5+
content(id: String!): Content
6+
@materializer(query: "content", arguments: [{ name: "id", argument: "id" }])
7+
author: Author
8+
lastUpdate: Date
99
}
1010

1111
type Content @mock {
@@ -15,36 +15,47 @@ type Content @mock {
1515
}
1616

1717
type Query {
18-
document: Document
19-
@rest(
20-
endpoint: "stepzen:empty"
21-
transforms: [{
22-
editor: """jq: {"author": { "name":"Roy Derks", "country":"Netherlands"}}"""
23-
}]
24-
)
25-
# Content is exposed here to keep the snippet self-contained, but would otherwise not be exposed as an operation
26-
content(id: String!): Content
27-
@connector(type:"echo")
18+
document: Document
19+
@rest(
20+
endpoint: "stepzen:empty"
21+
transforms: [
22+
{
23+
editor: """
24+
jq: {"author": { "name":"Roy Derks", "country":"Netherlands"}}
25+
"""
26+
}
27+
]
28+
)
29+
# Content is exposed here to keep the snippet self-contained, but would otherwise not be exposed as an operation
30+
content(id: String!): Content @connector(type: "echo")
2831
}
2932

3033
type Author {
31-
name: String!
32-
country: String
34+
name: String!
35+
country: String
3336
}
3437

3538
type Query {
3639
book: Book
3740
@rest(
38-
endpoint: "stepzen:empty"
39-
transforms: [{
40-
editor: """jq: {"refId": "27", "name": "Fullstack GraphQL"}"""
41-
}]
41+
endpoint: "stepzen:empty"
42+
transforms: [
43+
{
44+
editor: """
45+
jq: {"refId": "27", "name": "Fullstack GraphQL"}
46+
"""
47+
}
48+
]
4249
)
4350
}
4451

4552
type Book {
4653
refId: String!
4754
name: String
48-
author: Author @materializer (query: "document {author}")
49-
content: Content @materializer (query: "document {content}", arguments: {name: "id", field: "refId"})
50-
}
55+
author: Author @materializer(query: "document {author}")
56+
content: Content
57+
@materializer(
58+
query: "document {content}"
59+
arguments: { name: "id", field: "refId" }
60+
)
61+
}
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
schema @sdl(files:[
2-
"api.graphql"
3-
]){query: Query}
1+
schema @sdl(files: ["api.graphql"]) {
2+
query: Query
3+
}

materializer/nestedfieldselection/tests/Test.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
const {
22
deployAndRun,
3-
authTypes,
3+
stepzen,
44
getTestDescription,
55
} = require("../../../tests/gqltest.js");
66

@@ -24,8 +24,7 @@ describe(testDescription, function () {
2424
}
2525
}
2626
},
27-
authType: authTypes.adminKey,
2827
},
2928
]
30-
return deployAndRun(__dirname, tests);
29+
return deployAndRun(__dirname, tests, stepzen.admin);
3130
});

pocs/README.md

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# Developing PoCs.
2+
3+
## Sharing
4+
5+
When developing a GraphQL PoC using IBM API Connect Essentials (StepZen) you will typically
6+
want to share the endpoint to allow others to evaluate it by making GraphQL requests against it.
7+
8+
### Admin key
9+
10+
> [!CAUTION]
11+
> Never share an endpoint by handing out the account's adminkey (`stepzen whoami --adminkey`).
12+
13+
### API key
14+
15+
The most simple (but somewhat risky) approach is to share the account's apikey (`stepzen whoami --apikey`).
16+
17+
> [!WARNING]
18+
> The admin key grants access to all endpoints within an account. Thus if you are working on different PoCs, by providing access to one you provide access to all
19+
> which could leak information between different departments or clients.
20+
21+
### Obfuscated endpoints
22+
23+
Obfuscated endpoints allow sharing without handing out any keys or tokens.
24+
25+
The concept can include single-use or short-lived endpoints for a demos, or time-limited evaluations.
26+
27+
> [!WARNING]
28+
> Obfuscated endpoints are public, but have a hard to guess endpoint URL so anyone with the URL has access to the API.
29+
30+
See [obfuscated-endpoint-url](obfuscated-endpoint-url/README.md)
31+
32+
### JWT
33+
34+
_Coming Soon_!

0 commit comments

Comments
 (0)