Typings for Shopify Storefront API
npm install shopify-storefront-api-typings2020-04.
npm i -S shopify-storefront-api-typings
js
import { Checkout } from "shopify-storefront-api-typings";
`
Here is how you can get strongly typed queries with apollo:
`js
export const QUERY_CHECKOUT = gql
;
...
const { data } = useQuery<{ checkout: Checkout }>(QUERY_CHECKOUT);
`
Use the Partial<> utility if you want to create subsets of the type without getting type errors.
`js
const variant: Partial = { title: "Variant" };
`
Build your own typings
If you want to customise the namings or the Storefront API version you can build your own typings. To do that, you need to create a Private app with Storefront API enabled.
1. Clone this repository
`sh
git clone https://github.com/caki0915/shopify-storefront-api-typings.git
`
2. Rename .env.example to .env.
3. Inside .env add your Shopify Storefront API endpoint and access-token.
4. Run npm start`