0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

Apollo ServerのmockingでMockListが動かない

Last updated at Posted at 2021-05-13

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までの数字がランダムで決まるので、配列の数も可変にできるので、同じ仕様になりました。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?