Shopify Functions overview
What are Shopify Functions?Anchor link to section titled "What are Shopify Functions?"
Shopify Functions allow developers to customize the backend logic that powers parts of Shopify. The first place where we will allow you to extend logic is the discounting logic that lives inside of Checkout. Over time you will be able to manipulate the backend of many parts of Shopify.
How Shopify Functions workAnchor link to section titled "How Shopify Functions work"
Like a typical function you define an input, write the logic of your function, and then write out the output. Let’s dissect how each of these work:
- Input: The function input is a subset of the Cart API and is written as a GraphQL query. Functions can also query metafields so you can store necessary data and retrieve it.
- Function logic: The function logic can be written in any language that compiles to WebAssembly using WASI for
STDOUT. This approach ensures a low latency experience for buyers and merchants.
- Output: The function output is a payload that conforms to a GraphQL schema relevant to the specific domain. You can learn more about specific schemas in the Functions API reference.
Lifecycle of a Shopify FunctionAnchor link to section titled "Lifecycle of a Shopify Function"
The following diagram shows an example lifecycle of a Shopify Function:
App developers create and deploy apps that contain functions.
Merchants install the app on their Shopify store and configure the function. An API call is made with the function configuration.
Customers interact with a Shopify store and Shopify executes the function.
For example, an app developer might create and deploy an app with a function that defines a new discount type. The merchant can then install the app on their Shopify store and create a new discount from a discount type provided by the app. Shopify executes the function to calculate the discount when a customer adds a product to their cart.
Shopify Functions are never invoked directly by URL or otherwise. Shopify invokes them as-needed within the customer journey.
- Explore the references for each Function API.