Mock Transform
The mock
transform allow you to apply mocking for development usage.
To get started with this transform, install it from npm:
#
How to use?Add the following configuration to your Mesh config file:
The example above will replace the resolver of User.firstName
with a mock that uses faker.js
to generate a random name.
#
Codesandbox ExampleYou can check out our example that uses JSON Schema handler with mock data.
#
Config API Referenceif
(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 inmocks
. 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.firstNameif
(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