Stub data
Stub data is hard-coded into a task, providing an unchanging source of data for previews. It is an important tool when generating dynamic preview actions. Stub data may be used for user-defined variables, but may also override environment variables as needed.
For controlling preview event data (i.e. the values in event.data
, and values found in event subject variables), use defined preview events to cleanly specify these values outside of the task code.
Stubbing Liquid variables
Most tasks make decisions based on the Liquid variables automatically provided, making it a common practice to stub them during preview mode. Any and all Liquid variables may be replaced by stub data, including event
and any event subject variables.
In simple cases, replacement objects may be constructed using the assign tag.
The stub data in the following examples include an ID for the order, so as to generate a realistic tagsAdd mutation during preview mode.
Realistic preview actions are important for users and developers, but there's a functional importance for tagsAdd mutations in particular: in preview mode, Mechanic looks at the id
argument in order to determine what kind of resource will be tagged, in order to determine what permissions this particular mutation requires. If you generate tagsAdd mutations during preview, make sure to use realistic ID values!
It's also possible to construct this data using parse_json.
Stubbing GraphQL data
Mechanic makes GraphQL data available to tasks via the shopify filter. Mechanic observes the shopify filter in action during preview mode, using its inputs to inform Mechanic's knowledge of what permissions the task needs.
For this reason, it's important to allow the shopify filter to run normally, and construct stub data afterwards.
It can be useful to specify stub data using JSON, fed through the parse_json filter. Sample JSON is easy to generate using Shopify's GraphiQL app.
Last updated