Skip to content

Commit

Permalink
Update readme
Browse files Browse the repository at this point in the history
  • Loading branch information
cjkihl committed May 29, 2020
1 parent aafb6b7 commit 1154218
Showing 1 changed file with 16 additions and 11 deletions.
27 changes: 16 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,30 +18,35 @@ If you're looking for typings for **Shopify Storefront Api**, checkout the [shop
2. Import typings in your code. (vscode should find the typings and auto import for you).

```js
import { Checkout } from "shopify-admin-api-typings";
import { Order, OrderConnection } from "shopify-admin-api-typings";
```

Here is how you can get strongly typed queries with apollo:

```js
export const QUERY_CHECKOUT = gql`
query($id: ID!) {
checkout: node(id: $id) {
... on Checkout {
...CheckoutPartialFragment
```ts
const QUERY_ORDERS = gql`
query Orders {
orders(first: 5) {
edges {
node {
createdAt
}
}
}
}
${CheckoutFragment}
`;
...
const { data } = useQuery<{ checkout: Checkout }>(QUERY_CHECKOUT);

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.

```js
const variant: Partial<ProductVariant> = { title: "Variant" };
const variant: Partial<Order> = { name: "#001" };
```

## Build your own typings
Expand Down

0 comments on commit 1154218

Please sign in to comment.