Auto-generated Typescript type definitions for Shopify Admin API. Current version includes all types for version: 2020-04
.
If you're looking for typings for Shopify Storefront Api, checkout the shopify-storefront-api-typings package.
- Install package:
npm i -S shopify-admin-api-typings
- Import typings in your code. (vscode should find the typings and auto import for you).
import { Order, OrderConnection } from "shopify-admin-api-typings";
Here is how you can get strongly typed queries with apollo:
const QUERY_ORDERS = gql`
query Orders {
orders(first: 5) {
edges {
node {
createdAt
}
}
}
}
`;
const {
data: { orders },
} = await client.query<{ orders: OrderConnection }>({
query: QUERY_ORDERS,
});
Use the Partial<>
utility if you want to create subsets of the type without getting type errors.
const variant: Partial<Order> = { name: "#001" };
If you want to customise the namings or the Admin API version you can build your own typings. To do that, you need to create a Private app with Admin API enabled.
- Clone this repository
git clone https://github.com/caki0915/shopify-admin-api-typings.git
- Rename
.env.example
to.env
. - Inside
.env
add your Shopify Admin API endpoint and access-token. - Run
npm start