-
-
Notifications
You must be signed in to change notification settings - Fork 831
Description
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
graphql-tools/packages/mock/src/MockStore.ts
Line 493 in 99319be
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.