@@ -65,3 +65,96 @@ type Query {
6565 ]
6666 )
6767}
68+
69+
70+ # following are some JSONata examples
71+ # that replicate the object to array functionality or allow you to go directly to the customer
72+ # object in several different ways.
73+
74+ extend type Query {
75+
76+ # This replicates object2array
77+ customerAsNameValue_1 : JSON
78+ @rest (
79+ # See https://stepzen.com/docs/custom-graphql-directives/directives#ecmascript for more information on using `ecmascript`.
80+ endpoint : " stepzen:empty"
81+ ecmascript : " " "
82+ function transformREST(s) {
83+ return(JSON.stringify({" 1 ":{" fullName ":" John Doe ", " age ":23}, " 2 ":{" fullName ":" Jane Smith ", age: 25}}))
84+ }
85+ """
86+ # Transform the JSON using objectToArray.
87+ transforms : [
88+ {
89+ editor : " " "
90+ jsonata:$each($, function($value, $key) {
91+ { " name ": $key, " value ": $value }
92+ })
93+ """
94+ }
95+ ]
96+ )
97+
98+ customerAsCustomer_1 : JSON
99+ @rest (
100+ # See https://stepzen.com/docs/custom-graphql-directives/directives#ecmascript for more information on using `ecmascript`.
101+ endpoint : " stepzen:empty"
102+ ecmascript : " " "
103+ function transformREST(s) {
104+ return(JSON.stringify({" 1 ":{" fullName ":" John Doe ", " age ":23}, " 2 ":{" fullName ":" Jane Smith ", age: 25}}))
105+ }
106+ """
107+ # Transform the JSON using objectToArray.
108+ transforms : [
109+ {
110+ editor : " " "
111+ jsonata:$each($, function($value, $key) {
112+ { " id ": $key, " fullName ": $value.fullName, " age ": $value.age }
113+ })
114+ """
115+ }
116+ ]
117+ )
118+
119+ customerAsCustomer_2 : JSON
120+ @rest (
121+ # See https://stepzen.com/docs/custom-graphql-directives/directives#ecmascript for more information on using `ecmascript`.
122+ endpoint : " stepzen:empty"
123+ ecmascript : " " "
124+ function transformREST(s) {
125+ return(JSON.stringify({" 1 ":{" fullName ":" John Doe ", " age ":23}, " 2 ":{" fullName ":" Jane Smith ", age: 25}}))
126+ }
127+ """
128+ # Transform the JSON using objectToArray.
129+ transforms : [
130+ # this will transform into customers directly using the object transform operator
131+ # to merge a short key (named as id) fragment with the key's value.
132+ {
133+ editor : " " "
134+ jsonata:$each($, function($value, $key) {
135+ $value ~> |$| { " id ": $key } |
136+ })
137+ """
138+ }
139+ ]
140+ )
141+
142+ customerAsCustomer_3 : JSON
143+ @rest (
144+ # See https://stepzen.com/docs/custom-graphql-directives/directives#ecmascript for more information on using `ecmascript`.
145+ endpoint : " stepzen:empty"
146+ ecmascript : " " "
147+ function transformREST(s) {
148+ return(JSON.stringify({" 1 ":{" fullName ":" John Doe ", " age ":23}, " 2 ":{" fullName ":" Jane Smith ", age: 25}}))
149+ }
150+ """
151+ # Transform the JSON using objectToArray.
152+ transforms : [
153+ # this will transform into customers directly using the object transform operator
154+ # to merge a short key (named as id) fragment with the key's value.
155+ {
156+ editor : " " "jsonata:$each($, function($value, $key) { $merge([$value, {" id ": $key}]) })"""
157+ }
158+ ]
159+ )
160+ }
0 commit comments