The Run code action contains the following fields.
|Required. A GraphQL query to use data from previous steps as input to the Run code action.
|Required. A representation of the data to be returned by the action, defined in GraphQL's schema definition language (SDL).
Input data can be passed from steps that happen before the Run code action. To include this data, you can write a GraphQL query in the Input field. The data returned from the query will be available as the
input argument to the function marked with
export default. You don't need to handle paging or use
nodes in the query, as Flow handles those for you.
An example input that gets an order note and the title of a line item:
This data is converted to an
input variable that can be used in the code:
Inputs can also be destructured in the function signature:
The Run code action can return custom data. To define the type of the data that the code will return, use the Output field and GraphQL's Schema definition language (SDL). For example, to return a string called
giftMessage and a number called
You can also define a custom type to return more complex data. For example, to return a type called
Gift that contains a string called
message and a number called
To access this data in steps that follow this action, use the variable named Run code, which will be typed according to the
Output schema you define in the Run code action configuration. You can use this variable in both conditions and actions.
Examples for the code action can be found in the Flow examples repository.
The Run code action has the following limitations:
- Your code cannot import modules.
- Your code cannot make http calls (
- Your code cannot use
- Random and clock-based functions cannot be used. Date data, such as a
createdAtcan be passed in as an input.
In addition, the following limits are enforced:
- Input data query is limited to 5000 characters.
- Output data schema is limited to 5000 characters.
- Output data payload is limited to 50kb.
- Code cannot be longer than 50000 characters.
- Total execution duration is limited to 5 seconds.
- Memory usage is limited to 10MB.
The Flow team plans to add capabilities to the Run code action over time. The following table outlines the planned improvements and their estimated delivery dates.
|Bug fixes and cleanup
|Use `console.log` to output data to the Run log for troubleshooting purposes.
|Early April 2024
|External API calls
The Run code action is a new type of step in Shopify Flow. If you have feedback and questions, then please comment on this Flow community post.