Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow random list length to be configured by user #4263

Open
warrenday opened this issue Feb 22, 2022 · 0 comments
Open

Allow random list length to be configured by user #4263

warrenday opened this issue Feb 22, 2022 · 0 comments

Comments

@warrenday
Copy link

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

return [...new Array(randomListLength())].map(() => this.generateValueFromType(nullableType.ofType));

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant