breeze-sdk

This package contains all queries and mutations that are used in our sample storefront. It can be used for semi-custom or fully-custom (with ability to extend existing queries) storefront solutions.

Usage no npm install needed!

<script type="module">
  import breezeSdk from 'https://cdn.skypack.dev/breeze-sdk';
</script>

README

Breeze API SDK

This package contains all queries and mutations that are used in our sample storefront. Still under heavy development.

Setup

npm install breeze-sdk

Create new breeze client by using our built-in pre-configured apollo client:

import { createBreezeClient } from 'breeze-sdk'

const client = createBreezeClient(API_URL)

Usage

React

We provide a custom hook per each query that have near identical API to react-apollo but are dynamically typed, with built-in error handling.

In your root file:

import { BreezeProvider } from 'breeze-sdk'
import { client } from './breeze'

import App from './App'

const rootElement = document.getElementById('root')
ReactDOM.render(
  <BreezeProvider client={client}>
    <App />
  </BreezeProvider>,
  rootElement
)

There are 2 types of api calls - queries and mutations.

Query (gets data):

const { data: TData["data"], loading: boolean, error: ApolloError } = useProductDetails(variables, options?)

Mutation (sets data):

const [
  signIn: (options?) => Promise<TData>,
  { data: TData["data"], loading: boolean, error: ApolloError, called: boolean }
] = useSignIn(options?)

For options and full api reference, navigate to official docs

Other frameworks

Create new BreezeAPI instance and use methods available on it

import { BreezeAPI } from 'breeze-sdk'
import { client } from './breeze'

export const breezeAPI = new BreezeAPI(client)
const { data } = await breezeAPI.getProductDetails(variables, options?)

Local development

It is possible to develop storefront and SDK simultaneously. To do this, you need to link it to the storefront's project.

$ cd build
$ npm link
$ cd <your storefront path>
$ npm link breeze-sdk

Notice that in storefront webpack is configured to always resolve react to ./node_modules/react. It may seem redundant for the most use cases, but helps in sdk's local development, because it overcomes npm's limitations regarding peer dependencies hoisting, explicitely telling webpack to always have one and only copy of react.