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}}' +``` 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") ]"""} +]) + +}