# gatsby-plugin-apollo-shopify

> Gatsby plugin which injects a Shopify Apollo Client into the browser.

Latest version **1.1.0** (published 2020-07-30) · MIT license · 0 weekly downloads

## Install

```sh
npm install gatsby-plugin-apollo-shopify
pnpm add gatsby-plugin-apollo-shopify
yarn add gatsby-plugin-apollo-shopify
bun add gatsby-plugin-apollo-shopify
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.1.0 |
| Published | 2020-07-30 |
| First published | 2018-08-23 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 8 |
| Unpacked size | 6.9 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 22 |
| Author | Gil Greenberg |
| Maintainers | gilg |
| Keywords | graphql, apollo, gatsby-plugin, gatsbyjs, gatsby, shopify, shopify-storefront |

## Links

- npm: https://www.npmjs.com/package/gatsby-plugin-apollo-shopify
- Repository: https://github.com/gil--/gatsby-plugin-apollo-client
- Homepage: https://github.com/gil--/gatsby-plugin-apollo-client#readme
- Issues: https://github.com/gil--/gatsby-plugin-apollo-client/issues
- npm.io page: https://npm.io/package/gatsby-plugin-apollo-shopify

## Dependencies (8)

- [babel-cli](https://npm.io/package/babel-cli.md) ^6.26.0
- [react-apollo](https://npm.io/package/react-apollo.md) ^2.1.11
- [apollo-client](https://npm.io/package/apollo-client.md) ^2.4.0
- [babel-runtime](https://npm.io/package/babel-runtime.md) ^6.26.0
- [apollo-link-http](https://npm.io/package/apollo-link-http.md) ^1.5.4
- [babel-preset-react](https://npm.io/package/babel-preset-react.md) ^6.24.1
- [apollo-link-context](https://npm.io/package/apollo-link-context.md) ^1.0.8
- [apollo-cache-inmemory](https://npm.io/package/apollo-cache-inmemory.md) ^1.2.8

## Alternatives

- [apollo-link-http-common](https://npm.io/package/apollo-link-http-common.md) — 879.0K weekly downloads
- [react-relay](https://npm.io/package/react-relay.md) — 336.8K weekly downloads
- [relay-test-utils](https://npm.io/package/relay-test-utils.md) — 181.6K weekly downloads
- [@vendure/core](https://npm.io/package/@vendure/core.md) — 14.8K weekly downloads
- [@pnpm/deps.graph-sequencer](https://npm.io/package/@pnpm/deps.graph-sequencer.md) — 13.4K weekly downloads

## Recent versions

- 1.1.0 (latest) — 2020-07-30
- 1.0.2 — 2018-08-23
- 1.0.1 — 2018-08-23
- 1.0.0 — 2018-08-23

## README

# gatsby-plugin-apollo-shopify

## Install

`npm install --save gatsby-plugin-apollo-shopify`

## How to use

```js
// In your gatsby-config.js
plugins: [
  {
    resolve: `gatsby-plugin-apollo-shopify`,
    options: {
      shopName: `gatsbyjs`,
      accessToken: `48bbac10dae7225fe4e36a545d1b9b2f`,
      // Optionally set the API version you want to use. For a list of available API versions,
      // see: https://shopify.dev/concepts/about-apis/versioning/release-notes
      // Defaults to unspecified/oldest stable
      apiVersion: "2020-07",
    },
  },
]
```

## How to Query within Gatsby

To utilize the Apollo client within your Gatsby project, import `graphql-tag` and `react-apollo`. for example:

```js

import gql from "graphql-tag"
import { Query } from "react-apollo"

const GET_PRODUCT = gql`
  query($handle: String!) {
    shop {
      products(first:1, query: $handle) {
        edges {
          node {
            variants(first: 1) {
              edges {
                node {
                  availableForSale
                }
              }
            }
          }
        }
      }
    }
  }
`

export default ({ children, data }) => {
    const product = data.shopifyProduct

    return (
        <Query query={GET_PRODUCT} variables={{ handle: product.handle }}>
            {({ loading, error, data }) => {
                if (loading) return <div>Loading stock status...</div>
                if (error) return <div>There was an error!</div>

                return (
                <>
                    <h3>Stock Status: {data && data.shop.products && data.shop.products.edges[0].node.variants && data.shop.products.edges[0].node.variants.edges[0].node.availableForSale.toString()}</h3>
                </>
                )
            }}
        </Query>
    )
}

export const query = graphql`
    query productQuery($id: String!) {
        shopifyProduct(id: { eq: $id }) {
            handle
        }
    }
`

```

## Credits

Most of this plugin was taken from the [gatsby-plugin-apollo-client](https://github.com/gatsbyjs/gatsby/tree/master/examples/using-multiple-providers/plugins/gatsby-plugin-apollo-client) within the using-multiple-providers example site.

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