ardatan / ardatan/graphql-tools
Expose mock store reset as a top level boolean control when creating schema for mock server
- 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.**
See detailed description of the problem at https://stackoverflow.com/questions/79634678/graphql-tools-mock-does-not-produce-randomized-response-on-repeated-gql-requests.
**Describe the solution you'd like**
Currently the [official doc on mocking](https://the-guild.dev/graphql/tools/docs/mocking) does not provide guidance on how the mock store can be reset upon each request.
```javascript
// Fill this in with the schema string
const schemaString = `...`
// Make a GraphQL schema with no resolvers
const schema = makeExecutableSchema({ typeDefs: schemaString })
// Create a new schema with mocks
const schemaWithMocks = addMocksToSchema({ schema })
```
In scenarios where a developer needs refreshed data response upon each new request towards the mock server, currently the only solution seems to be creating a mock store ahead of time, and add an HTTP request interceptor to reset the mock store. It would be nicer this can be exposed to the `addMocksToSchema` interface like below. And implementation of the mock store is revised accordingly to support that.
```
const schemaWithMocks = addMocksToSchema({ schema, resetMockStore: true });
```
Or if there is any other better alternative for clients to configure this, that will be even greater.
**Describe alternatives you've considered**
See a [workaround](https://stackoverflow.com/a/79636176/4993386) in the answer of the same SO post.
Contributor guide
Research direction
Start at the addMocksToSchema interface and review the official mocking documentation and linked workaround. Trace how the mock store is created and determine how a top-level resetMockStore option would define request boundaries. Done means the chosen configuration resets mocked data for each request and the behavior is documented.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- api
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100