回答編集履歴
3
コード追加
answer
CHANGED
@@ -52,4 +52,20 @@
|
|
52
52
|
???? [codepen.io/kilesa/pen/GRvEwPR](https://codepen.io/kilesa/pen/GRvEwPR?editors=0010)
|
53
53
|
|
54
54
|
|
55
|
-
GraphQLの仕様の詳細は確認しておりませんので、要件と異なる点などあれば、コメントからご教示ください。
|
55
|
+
GraphQLの仕様の詳細は確認しておりませんので、要件と異なる点などあれば、コメントからご教示ください。
|
56
|
+
|
57
|
+
### 追記
|
58
|
+
|
59
|
+
上記の回答では、lodash の _.omit を使いましたが、同じくlodashの [_.mapValues](https://lodash.com/docs/#mapValues) を使えば、`convert()`関数を以下のように書けました。(再帰の深さの上限は、先と同じく50としています。)
|
60
|
+
|
61
|
+
```javascript
|
62
|
+
const convert = (obj, depth = 0) =>
|
63
|
+
depth === 50
|
64
|
+
? {}
|
65
|
+
: _.mapValues(obj, value =>
|
66
|
+
value.edges
|
67
|
+
? value.edges.map(({ node }) => convert(node, depth + 1))
|
68
|
+
: value,
|
69
|
+
);
|
70
|
+
```
|
71
|
+
???? [codepen.io/kilesa/pen/MWvoMgy](https://codepen.io/kilesa/pen/MWvoMgy?editors=0010)
|
2
コード追加
answer
CHANGED
@@ -7,7 +7,7 @@
|
|
7
7
|
return { [edgesHolderProp]: [] };
|
8
8
|
}
|
9
9
|
|
10
|
-
const nodes = obj[edgesHolderProp].edges.map(
|
10
|
+
const nodes = obj[edgesHolderProp].edges.map(e => {
|
11
11
|
const node = _.omit(e.node, 'images');
|
12
12
|
if (e.node.images) {
|
13
13
|
const { images } = convert(e.node, 'images', depth + 1);
|
1
コード追加
answer
CHANGED
@@ -4,7 +4,7 @@
|
|
4
4
|
```javascript
|
5
5
|
function convert(obj, edgesHolderProp = 'products', depth = 0) {
|
6
6
|
if (depth === 50) {
|
7
|
-
return {
|
7
|
+
return { [edgesHolderProp]: [] };
|
8
8
|
}
|
9
9
|
|
10
10
|
const nodes = obj[edgesHolderProp].edges.map((e, i) => {
|