From 4c514b6f9dea3346c2fb48519a881946288fadcc Mon Sep 17 00:00:00 2001 From: asararatnakar Date: Tue, 28 Jan 2025 11:23:17 -0500 Subject: [PATCH 1/4] chore: fix the json object values and README Signed-off-by: asararatnakar --- transforms/README.md | 2 +- transforms/jsonobjectToJsonarray/api.graphql | 9 +++++++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/transforms/README.md b/transforms/README.md index ec4f038..527c673 100644 --- a/transforms/README.md +++ b/transforms/README.md @@ -8,5 +8,5 @@ For more on what `transforms` is and how it operates within the custom `@rest` d - [filter](filter) shows how the response of a REST API can be filtered - [combineintostring](combineintostring) shows how a new field in the return type can be created by concatenating some other fields (like address parts into one address) -- [jsonobjectToJsonarray](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 +- [jsonarrayToJsonobject](jsonarrayToJsonobject) 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 - [jsonobjectToJsonarray](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. diff --git a/transforms/jsonobjectToJsonarray/api.graphql b/transforms/jsonobjectToJsonarray/api.graphql index 763a5bf..20fb8af 100644 --- a/transforms/jsonobjectToJsonarray/api.graphql +++ b/transforms/jsonobjectToJsonarray/api.graphql @@ -61,10 +61,15 @@ type Query { # you could comment this out if you want to try setters instead { pathpattern: ["[]*"] - editor: "jq:.[]|{id:.name,fullName:.value.name,age:.value.age}" + editor: "jq:.[]|{id:.name,fullName:.value.fullName,age:.value.age}" } ] # for the second transformation, you can use setters. Uncomment the next line and comment the second pathpattern line above to see how it operates. - # setters: [{field: "id", path: "name"}, {field:"fullName", path: "value.age"}, {field:"age", path:"value.fullName"}] + # for this to work change the return type from JSON to [Customer] + # setters: [ + # { field: "id", path: "name" } + # { field: "fullName", path: "value.fullName" } + # { field: "age", path: "value.age" } + # ] ) } From a4ef6587543ea8959c722d43f059e544476268b3 Mon Sep 17 00:00:00 2001 From: asararatnakar Date: Tue, 28 Jan 2025 13:15:08 -0500 Subject: [PATCH 2/4] update comments Signed-off-by: asararatnakar --- .gitignore | 3 ++- transforms/jsonobjectToJsonarray/api.graphql | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/.gitignore b/.gitignore index 1dcef2d..a1cbec1 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ node_modules -.env \ No newline at end of file +.env +.vscode \ No newline at end of file diff --git a/transforms/jsonobjectToJsonarray/api.graphql b/transforms/jsonobjectToJsonarray/api.graphql index 20fb8af..fd30da3 100644 --- a/transforms/jsonobjectToJsonarray/api.graphql +++ b/transforms/jsonobjectToJsonarray/api.graphql @@ -65,7 +65,7 @@ type Query { } ] # for the second transformation, you can use setters. Uncomment the next line and comment the second pathpattern line above to see how it operates. - # for this to work change the return type from JSON to [Customer] + # In order to make this to work, change the return type from JSON to [Customer] # setters: [ # { field: "id", path: "name" } # { field: "fullName", path: "value.fullName" } From 241d5c48bffd3465beb4239804c87058319534cf Mon Sep 17 00:00:00 2001 From: asararatnakar Date: Tue, 28 Jan 2025 13:13:43 -0500 Subject: [PATCH 3/4] update the comments Signed-off-by: asararatnakar --- transforms/jsonobjectToJsonarray/api.graphql | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/transforms/jsonobjectToJsonarray/api.graphql b/transforms/jsonobjectToJsonarray/api.graphql index fd30da3..7e71d44 100644 --- a/transforms/jsonobjectToJsonarray/api.graphql +++ b/transforms/jsonobjectToJsonarray/api.graphql @@ -64,8 +64,10 @@ type Query { editor: "jq:.[]|{id:.name,fullName:.value.fullName,age:.value.age}" } ] + # for the second transformation, you can use setters. Uncomment the next line and comment the second pathpattern line above to see how it operates. - # In order to make this to work, change the return type from JSON to [Customer] + # In order to make this to work, change the return type from JSON to [Customer]. + # setters: [ # { field: "id", path: "name" } # { field: "fullName", path: "value.fullName" } From 99b3bd7314ee26fe222fe127d859cec45c02ee01 Mon Sep 17 00:00:00 2001 From: asararatnakar Date: Tue, 28 Jan 2025 13:16:03 -0500 Subject: [PATCH 4/4] remove empty line Signed-off-by: asararatnakar --- .gitignore | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index a1cbec1..a377996 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ node_modules .env -.vscode \ No newline at end of file +.vscode +