Apollo ServerのmockingでMockListが動かない
開発段階などでmockingが便利。でもデフォルトだと2件しか取れなくて困る。
公式だとMockListの使用が書いてある
Person: () => ({
// a list of length between 2 and 6 (inclusive)
friends: () => new MockList([2,6]),
// a list of three lists each with two items: [[1, 1], [2, 2], [3, 3]]
listOfLists: () => new MockList(3, () => new MockList(2)),
}),
"message": "Expected Iterable, but did not find one for field (field名)"
と言うエラーが出て利用できない。
空配列を入れるといいみたい
詳しく調べると、依存しているgraphQltoolsで更新があったみたい
Deprecated: MockList
MockList is deprecated, use plain arrays instead. See Using lists in mocks.
{
Person: () => ({
// a list of length between 2 and 6
friends: [...new Array(casual.integer(2, 6))],
// a list of three lists of two items: [[1, 1], [2, 2], [3, 3]]
listOfLists: () => [...new Array(3)].map((i) => [...new Array(2)]),
}),
}
単純に空の配列を渡せばよしなにしてくれるようです。
casual.integer(2,6)で2から6までの数字がランダムで決まるので、配列の数も可変にできるので、同じ仕様になりました。