Skip to content

Allow random list length to be configured by user #4263

@warrenday

Description

@warrenday

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions