Skip to content

Latest commit

 

History

History
215 lines (144 loc) · 10.4 KB

README.md

File metadata and controls

215 lines (144 loc) · 10.4 KB

Shopify App Template - Remix

This is a template for building a Shopify app using the Remix framework.

Quick start

Prerequisites

  1. You must download and install Node.js if you don't already have it.
  2. You must create a Shopify partner account if you don’t have one.
  3. You must create a store for testing if you don't have one, either a development store or a Shopify Plus sandbox store.

Setup

If you used the CLI to create the template, you can skip this section.

Using yarn:

yarn install

Using npm:

npm install

Using pnpm:

pnpm install

Local Development

Using yarn:

yarn dev

Using npm:

npm run dev

Using pnpm:

pnpm run dev

Press P to open the URL to your app. Once you click install, you can start development.

Local development is powered by the Shopify CLI. It logs into your partners account, connects to an app, provides environment variables, updates remote config, creates a tunnel and provides commands to generate extensions.

Authenticating and querying data

To authenticate and query data you can use the shopify const that is exported from /app/shopify.server.js:

export async function loader({ request }) {
  const { admin } = await shopify.authenticate.admin(request);

  const response = await admin.graphql(`
    {
      products(first: 25) {
        nodes {
          title
          description
        }
      }
    }`);

  const {
    data: {
      products: { nodes },
    },
  } = await response.json();

  return json(nodes);
}

This template come preconfigured with examples of:

  1. Setting up your Shopify app in /app/shopify.server.js
  2. Querying data using Graphql. Please see: /app/routes/app._index.jsx.
  3. Responding to mandatory webhooks in /app/routes/webhooks.jsx

Please read the documentation for @shopify/shopify-app-remix to understand what other API's are available.

Deployment

Application Storage

This template uses Prisma to store session data, by default using an SQLite database. The database is defined as a Prisma schema in prisma/schema.prisma.

This use of SQLite works in production if your app runs as a single instance. The database that works best for you depends on the data your app needs and how it is queried. You can run your database of choice on a server yourself or host it with a SaaS company. Here’s a short list of databases providers that provide a free tier to get started:

Database Type Hosters
MySQL SQL Digital Ocean, Planet Scale, Amazon Aurora, Google Cloud SQL
PostgreSQL SQL Digital Ocean, Amazon Aurora, Google Cloud SQL
Redis Key-value Digital Ocean, Amazon MemoryDB
MongoDB NoSQL / Document Digital Ocean, MongoDB Atlas

To use one of these, you can use a different datasource provider in your schema.prisma file, or a different SessionStorage adapter package.

Build

Remix handles building the app for you, by running the command below with the package manager of your choice:

Using yarn:

yarn build

Using npm:

npm run build

Using pnpm:

pnpm run build

Hosting

When you're ready to set up your app in production, you can follow our deployment documentation to host your app on a cloud provider like Heroku or Fly.io.

When you reach the step for setting up environment variables, you also need to set the variable NODE_ENV=production.

Gotchas / Troubleshooting

Database tables don't exist

If you run the app right after creating it, you'll get this error:

The table `main.Session` does not exist in the current database.

This will happen when the Prisma database hasn't been created. You can solve this by running the setup script in your app.

Navigating to other pages breaks

In Remix apps, you can navigate to a different page either by adding an <a> tag, or using the <Link> component from @remix-run/react.

In Shopify Remix apps you should avoid using <a>. Use <Link> from @remix-run/react instead. This ensures that your user remains authenticated.

Non Embedded

Shopify apps are best when they are embedded into the Shopify Admin. This template is configured that way. If you have a reason to not embed your please make 2 changes:

  1. Remove the <script/> tag to App Bridge in /app/routes/app.jsx
  2. Remove any use of App Bridge APIs (window.shopify) from your code
  3. Update the config for shopifyApp in app/shopify.server.js. Pass isEmbedded: false

Benefits

Shopify apps are built on a variety of Shopify tools to create a great merchant experience.

The Remix app template comes with the following out-of-the-box functionality:

  • OAuth: Installing the app and granting permissions
  • GraphQL Admin API: Querying or mutating Shopify admin data
  • REST Admin API: Resource classes to interact with the API
  • Webhooks: Callbacks sent by Shopify when certain events occur
  • AppBridge: This template uses the next generation of the Shopify App Bridge library.
    • This library is currently in development and works in unison with the current Shopify App Bridge library.
  • Polaris: Design system that enables apps to create Shopify-like experiences

Tech Stack

This template uses Remix. The following Shopify tools are also included to ease app development:

  • Shopify App Remix provides authentication and methods for interacting with Shopify APIs.
  • Shopify App Bridge allows your app to seamlessly integrate your app within Shopify's Admin.
  • Polaris React is a powerful design system and component library that helps developers build high quality, consistent experiences for Shopify merchants.
  • Webhooks: Callbacks sent by Shopify when certain events occur
  • Polaris: Design system that enables apps to create Shopify-like experiences

Note: This template runs on JavaScript, but it's fully set up for TypeScript. If you want to create your routes using TypeScript, we recommend removing the noImplicitAny config from tsconfig.json

Resources