Skip to content
Open
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
28 changes: 28 additions & 0 deletions transforms/filter/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
### Tranforms: Filtering

## ECMAScript

The `ecmascript` argument is great for writing filters.
See https://stepzen.com/docs/custom-graphql-directives/directives#ecmascript for more information on `ecmascript`.
We are picturing a real-life scenario in which you call a backend using the `endpoint` argument.
See https://stepzen.com/docs/connecting-backends/how-to-connect-a-rest-service for more information on `@rest`.

### Quick try
```
stepzen deploy
stepzen request '{customer(name: "John Doe") {id name}}'
```

## JSONata

JSONata transforms provdes an alternate method for filtering
customer_1 uses the `[ ... ]` filter to return all "customers" (`$`) that
contain `name = the argument name`

The outer array constructor `[]` is used to defeat singleton sequence equivalence.

### Quick try
```
stepzen deploy
stepzen request '{customer_1(name: "John Doe") {id name}}'
```
14 changes: 14 additions & 0 deletions transforms/filter/api.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,17 @@ type Query {
"""
)
}

# jsonata transforms provdes an alternate method for filtering
# customer_1 uses the [ ... ] filter to return all "customers" ($) that
# contain name = the argument name
# jsonata has quirks: if you leave out the outer []

extend type Query {
customer_1(name: String!): [Customer]
@rest(
endpoint: "https://sample-api.us-east-a.apiconnect.automation.ibm.com/api/customers"
transforms: [ { editor:"""jsonata:$[name = $get("name") ]"""}
])

}