ardatan / ardatan/graphql-tools

Allow random list length to be configured by user

Open
#4,263 0 comments 4 reactions 0 assignees View on GitHub
Dominant language
TypeScript
Stars
5.4k
Forks
830
Avg merge
10h 59m
Merged PRs (30d)
45

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 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.

Contributor guide

Open the contributing guide

Research direction

Start in packages/mock/src/MockStore.ts at the linked randomListLength implementation, then trace how addMocksToSchema accepts configuration. Define the requested default list-length option so an unspecified array can produce length 0, and verify that explicit array mocks remain unaffected.

Written by the indexing model from the issue text.

Assessment

Tech stack
graphql, typescript
Domain
api, testing
Issue type
Feature
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.