Start building your app
In this tutorial, you'll accomplish a series of tasks to add some specific functionality to your app. Your final app will be simple, but you’ll learn where to find resources to build more complex features on your own.
You want to create an app that helps merchants manage their product inventory. Merchants will use your app to document important details about their products, including product names and prices.
Inventory management is the process of organizing and managing stock throughout the supply chain. Effective inventory management is critical for ensuring that a business has enough stock to meet customer demand.
By providing inventory management capabilities, your app will help merchants have a better chance of making a profit and being successful.
What you'll learn
After you've finished this tutorial, you'll have accomplished the following:
- populated products in your development store to test your app against
- built the beginnings of your user interface with Polaris
- set up a GraphQL query to retrieve products
- set up a GraphQL mutation to update the prices of products
- You've completed the create an app quickstart.
- You have a code editor installed on your computer, such as VSCode or Atom.
Step 1: Populate products
Shopify CLI helps with the process of adding example data to test your app's behavior. You can use Shopify CLI to create records for products, customers, and draft orders.
Because your app needs to interact with product data, start by populating products in your development store:
- Open a new terminal window.
- Navigate to your project directory.
shopify populate products.
Step 2: Add an empty state
Now that you can run your app in Shopify, you can view and test your frontend components as you build them. You can use Polaris, Shopify’s React component library and design system, to build your user interface.
Use Polaris to add an empty state to your app. The Polaris Empty state component helps to communicate the value of your app and its primary action when merchants first add it to their Shopify admin.
- In your code editor, navigate to your
Replace the contents of the file with an
When you preview your embedded app, it displays the empty state.
Step 3: Add a resource picker
The App Bridge
ResourcePicker action set provides a search-based interface to help you find and select one or more products and then returns the selected resources to your app.
pages/index.jsfile, add a class that sets a state for the resource picker. Then, add the
ResourcePickercomponent to the primary action button on the
In your embedded app, when you click Select products, the Add products modal opens.
Step 4: Add a resource list
Now that you've set up your resource picker, you need a way to retrieve products. You can retrieve products using the GraphQL Admin API. Ultimately, you want to display these products in a resource list.
To allow your app to query data with GraphQL, create a new
ResourceList.js file and include the
react-apollo imports in the file.
Then, set up a GraphQL query called
getProducts to retrieve a list of products and their prices.
npm install store-js.
store-jsto persist data for testing purposes in your app.
Create a new
componentsfolder in the
pagesfolder in your project, and create a new
ResourceList.jsfile in the folder.
Add imports to your
ResourceList.jsfile and set up your GraphQL query to retrieve products and their prices:
ResourceList.jsfile, after your GraphQL query, set up a class called
ResourceListWithProductsthat extends the
ResourceListcomponent and returns products and prices. Then, define your
pages/index.jsfile, add your imports and define a constant for your app's empty state. Then, update the code that controls the layout of your empty state, and specify using your new resource list with products:
Now, when you click Select products, and add products from the Add products modal, a list of products displays.
Step 5: Update product prices
You've implemented a GraphQL query to read product data, and added the functionality to display the retrieved products in a resource list. Next, you'll use GraphQL to modify product data.
Set up a GraphQL mutation called
ProductVariantUpdate to update the prices of products in your app.
- Create a new
ApplyRandomPrices.jsfile in your
Add imports to your
ApplyRandomPrices.jsfile and set up a GraphQL mutation that allows your app to update the prices of products:
After your mutation in
ApplyRandomPrices.js, set up a class called
ApplyRandomPriceswhich takes your mutation's input and applies a random price to the selected product:
pages/index.jsfile to include the following imports:
ResourceList.js, add the
ApplyRandomPricesimport. Implement a constructor on your
ResourceListWithProductsclass and update your GraphQL query to enable refetching products by ID. Finally, update your
In your app, you can now update the prices of products.
- Use webhooks to stay in sync with Shopify or execute code after a specific event occurs in a shop.
- Identify your app business model and learn how to use the Billing API to bill customers with recurring monthly charges or one-time purchases.
- Learn how to use app extensions to add features to Shopify admin or POS.
- Explore the GraphQL Admin API and REST Admin API references.