Skip to content

Remove randomness from addMockFunctionsToSchema #1231

@Mathieuu

Description

@Mathieuu

I would like to understand the reason why addMockFunctionsToSchema introduces randomness.

https://github.com/apollographql/graphql-tools/blob/7eaf4e19f48e85425d45d31830eb607805542fb9/src/mock.ts#L53

And

https://github.com/apollographql/graphql-tools/blob/7eaf4e19f48e85425d45d31830eb607805542fb9/src/mock.ts#L196

Those resolvers are the ultimate fallback if the user don't provide a mocked implementation. If the user forget to override them, random values are going to be sent in the tests.

I had a viewerPermission resolver that returned an enumeration: READ, WRITE . Because I forgot to override the resolver, my interface was rendered in read-only mode half of the time.

I think any test helper function should aim at consistency between two test run. Otherwise we get flaky tests and hard to debug problems. If users want random data, let them override the default implementation themselves.

Am I missing a reason why we need randomness in that file?

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