From 1a7254c813de328702c78664fb2e5cd23ed84174 Mon Sep 17 00:00:00 2001 From: "Charlie C. Kim" <13868028+cckim@users.noreply.github.com> Date: Thu, 11 Dec 2025 18:04:31 -0800 Subject: [PATCH 1/2] add a jsonata example, readme --- transforms/filter/README.md | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 transforms/filter/README.md diff --git a/transforms/filter/README.md b/transforms/filter/README.md new file mode 100644 index 0000000..9213015 --- /dev/null +++ b/transforms/filter/README.md @@ -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}}' +``` From ddbabc5b9c572babb5b49ff1fbe31ff17366e786 Mon Sep 17 00:00:00 2001 From: "Charlie C. Kim" <13868028+cckim@users.noreply.github.com> Date: Fri, 12 Dec 2025 09:03:38 -0800 Subject: [PATCH 2/2] jsonata version --- transforms/filter/api.graphql | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/transforms/filter/api.graphql b/transforms/filter/api.graphql index d2c2f64..da65055 100644 --- a/transforms/filter/api.graphql +++ b/transforms/filter/api.graphql @@ -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") ]"""} +]) + +}