# gridsome-source-shopify-v2

> Shopify source plugin for Gridsome

Latest version **0.1.4** (published 2019-11-19) · MIT license · 0 weekly downloads

> **Deprecated.** This package is deprecated.

## Install

```sh
npm install gridsome-source-shopify-v2
pnpm add gridsome-source-shopify-v2
yarn add gridsome-source-shopify-v2
bun add gridsome-source-shopify-v2
```

## Health

**Score 10/100 (F)** — status: deprecated.

Negative: deprecated.

## Facts

| | |
|---|---|
| Version | 0.1.4 |
| Published | 2019-11-19 |
| First published | 2019-11-19 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 3 |
| Unpacked size | 20.9 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Travis Reynolds |
| Maintainers | travisreynolds |
| Keywords | gridsome, gridsome-plugin, gridsome-source, shopify |

## Links

- npm: https://www.npmjs.com/package/gridsome-source-shopify-v2
- npm.io page: https://npm.io/package/gridsome-source-shopify-v2

## Dependencies (3)

- [camelcase](https://npm.io/package/camelcase.md) ^5.3.1
- [prettyjson](https://npm.io/package/prettyjson.md) ^1.2.1
- [graphql-request](https://npm.io/package/graphql-request.md) ^1.8.2

## Alternatives

- [@sindresorhus/slugify](https://npm.io/package/@sindresorhus/slugify.md) — 3.7M weekly downloads
- [solid-js](https://npm.io/package/solid-js.md) — 2.7M weekly downloads
- [expo-glass-effect](https://npm.io/package/expo-glass-effect.md) — 2.5M weekly downloads
- [nanoassert](https://npm.io/package/nanoassert.md) — 780.8K weekly downloads
- [@ffmpeg/ffmpeg](https://npm.io/package/@ffmpeg/ffmpeg.md) — 529.5K weekly downloads

## Recent versions

- 0.1.4 (latest) — 2019-11-19
- 0.1.3 — 2019-11-19
- 0.1.2 — 2019-11-19
- 0.1.1 — 2019-11-19
- 0.1.0 — 2019-11-19

## README

# gridsome-source-shopify-v2

> Shopify source plugin for Gridsome

This plugin also support the Storefront API's `transformedSrc` image field. You can create different image size and scales with this, for example creating a thumbnail image.

## Usage

`gridsome.config.js`
```js
module.exports = {
  plugins: [
    {
      use: 'gridsome-source-shopify-v2',
      options: {
        storeName: 'my-store' // OR
        storeUrl: 'https://<my-store>.myshopify.com',
        storefrontToken: <storefront api token>, //Required
        typeName: 'Shopify' // Optional, default is 'Shopify'
        types: [ 'Product', 'Collection' ], // Optional, default is all types
        perPage: 100 // Optional, default is 100
      }
    }
  ]
}
```

## Routes & Templates

Now you can create a template called `ShopifyProduct.vue`, and specify the route for it - Gridsome will automatically generate pages for all products.

`gridsome.config.js`
```js
module.exports = {
  templates: {
      ShopifyProduct: '/product/:handle'
  }
}
```

You can also specify templates to use if you do not want to name the template files `Shopify<type>`, or if you want to change the page routes:

`gridsome.config.js`
```js
module.exports = {
  templates: {
      ShopifyProduct: [
        {
          path: '/product/:handle',
          component: './src/templates/Product.vue'
        }
      ],
      ShopifyCollection: [
        {
          path: '/collection/:handle',
          component: './src/templates/Collection.vue'
        }
      ]
    },
  }
  ```

## Page Query

Once you have specified the route for a type, you can query it by ID.

```vue
<page-query>
query Product ($id: ID!) {
  shopifyProduct (id: $id) {
    id
    descriptionHtml
    title
  }
}
</page-query>
```

Now this product will be available at `this.$page.shopifyProduct`:
```vue
<template>
  <Layout>
    <h1>{{ $page.shopifyProduct.title }}</h3>
    <div v-html="$page.shopifyProduct.descriptionHtml" />
  </Layout>
</template>
```

## Example Queries

### Products

```graphql
{
  allShopifyProduct {
    edges {
      node {
        id
        title
        handle
        descriptionHtml
        image {
          originalSrc
          thumbnail: transformedSrc(maxWidth: 100, maxHeight: 100, crop: CENTER)
        }
        collections {
          title
          slug
        }
        tags
        productType
      }
    }
  }
}
```

### Product's Variants

### Products

```graphql
{
  allShopifyProduct {
    edges {
      node {
        id
        variants {
          title
          image {
            id
            altText
            originalSrc
          }
          price {
            amount
            currencyCode
          }
          selectedOptions {
            name
            value
          }
        }
      }
    }
  }
}
```

### Collections

```graphql
{
  allShopifyCollection {
    edges {
      node {
        id
        title
        slug
        descriptionHtml
        image {
          id
          altText
          banner: transformedSrc(maxHeight: 400, crop: BOTTOM, scale: 2)
        }
        products {
          id
          title
          slug
        }
      }
    }
  }
}
```

### Articles

```graphql
{
  allShopifyArticle (limit: 10) {
    edges {
      node {
        id
        title
        publishedAt
        author {
          name
        }
        blog {
          id
          title
        }
        contentHtml
        excerptHtml
        image {
          id
          altText
          originalSrc
        }
      }
    }
  }
}
```

### Pages

```graphql
{
  allShopifyPage {
    edges {
      node {
        id
        title
        handle
        bodySummary
        body
      }
    }
  }
}
```

---
_Source: https://npm.io/package/gridsome-source-shopify-v2 · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
