Mock Transform

The mock transform allow you to apply mocking for development usage.

To get started with this transform, install it from npm:

yarn add @graphql-mesh/transform-mock

How to use?

Add the following configuration to your Mesh config file:

transforms:
- mock:
mocks:
- apply: User.firstName
faker: '{{name.firstName}}'

The example above will replace the resolver of User.firstName with a mock that uses faker.js to generate a random name.

Codesandbox Example

You can check out our example that uses JSON Schema handler with mock data.

Config API Reference

  • if (type: Boolean) - If this expression is truthy, mocking would be enabled You can use environment variables expression, for example: ${MOCKING_ENABLED}
  • preserveResolvers (type: Boolean) - Do not mock any other resolvers other than defined in mocks. For example, you can enable this if you don't want to mock entire schema but partially.
  • mocks (type: Array of Object) - Mock configurations:
    • apply (type: String, required) - Resolver path Example: User.firstName
    • if (type: Boolean) - If this expression is truthy, mocking would be enabled You can use environment variables expression, for example: ${MOCKING_ENABLED}
    • faker (type: String) - Faker.js expression or function Read more (https://github.com/marak/Faker.js/#fakerfake) Example; faker: name.firstName faker: "{{ name.firstName }} {{ name.lastName }}"
    • custom (type: String) - Custom mocking It can be a module or json file. Both "moduleName#exportName" or only "moduleName" would work