graphql-tools icon indicating copy to clipboard operation
graphql-tools copied to clipboard

Allow random list length to be configured by user

Open warrenday opened this issue 3 years ago • 0 comments

Is your feature request related to a problem? Please describe.

Arrays produce unpredictable results when a mock is not explicitly provided.

Describe the solution you'd like

When arrays are not explicitly given a mock they will default to a length of 2 according to the return value of randomListLength. See https://github.com/ardatan/graphql-tools/blob/99319bea39b070aa4ea5b79f4d0d8c72824bf8a5/packages/mock/src/MockStore.ts#L493

If each entry in the array is an object, this can result in unpredictable results as all the values of the objects will also be auto-filled. It would be really useful to be able to manually configure the mock store to return arrays of length 0.

When calling addMocksToSchema an argument could be provided.

addMocksToSchema({ schema, defaultListLength: 0 })

Describe alternatives you've considered

The alternative is to manually provide a mock of [] for all queries you wish to be consistent, but this takes away much of the value of leaving the auto-mocking to handle most of the load.

I am happy to work on this issue but want to gauge interest.

warrenday avatar Feb 22 '22 18:02 warrenday