8000 Expose mock store reset as a top level boolean control when creating schema for mock server · Issue #7217 · ardatan/graphql-tools · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content
Expose mock store reset as a top level boolean control when creating schema for mock server #7217
Open
@MaRuifeng

Description

@MaRuifeng

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 does not provide guidance on how the mock store can be reset upon each request.

// 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 in the answer of the same SO post.

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

      0