Skip to content

Commit

Permalink
Admin Api Typings
Browse files Browse the repository at this point in the history
  • Loading branch information
cjkihl committed May 29, 2020
1 parent 31161dc commit 6329620
Show file tree
Hide file tree
Showing 5 changed files with 40,260 additions and 7,824 deletions.
2 changes: 1 addition & 1 deletion .env.example
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
STOREFRONT_ENDPOINT=<Shopify Storefront API Endpoint>
ADMIN_ENDPOINT=<Shopify Admin API Endpoint> (https://{shop}.myshopify.com/admin/api/2020-04/graphql.json)
ACCESS_TOKEN=<Shopify Storefront API Access Token>
14 changes: 7 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
# Shopify Storefront API Types
# Shopify Admin API Types

![Dependencies](https://img.shields.io/badge/dependencies-up%20to%20date-brightgreen.svg)
![Contributions welcome](https://img.shields.io/badge/contributions-welcome-orange.svg)
[![License](https://img.shields.io/badge/license-MIT-blue.svg)](https://opensource.org/licenses/MIT)

## Overview

Auto-generated Typescript typings for Shopify Storefront API. Current version includes all types for version: `2020-04`.
Auto-generated Typescript typings for Shopify Admin API. Current version includes all types for version: `2020-04`.

![types](https://user-images.githubusercontent.com/1438153/72280575-eb2ec200-3638-11ea-9609-4196400219f5.jpg)

## How to use

1. Install package: `npm i -S shopify-storefront-api-typings`
1. Install package: `npm i -S shopify-admin-api-typings`
2. Import typings in your code. (vscode should find the typings and auto import for you).

```js
import { Checkout } from "shopify-storefront-api-typings";
import { Checkout } from "shopify-admin-api-typings";
```

Here is how you can get strongly typed queries with apollo:
Expand Down Expand Up @@ -44,14 +44,14 @@ const variant: Partial<ProductVariant> = { 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.
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.

1. Clone this repository

```sh
git clone https://github.com/caki0915/shopify-storefront-api-typings.git
git clone https://github.com/caki0915/shopify-admin-api-typings.git
```

2. Rename `.env.example` to `.env`.
3. Inside `.env` add your Shopify Storefront API endpoint and access-token.
3. Inside `.env` add your Shopify Admin API endpoint and access-token.
4. Run `npm start`
10 changes: 5 additions & 5 deletions generateSchema.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,19 @@ const { buildClientSchema } = require("graphql/utilities/buildClientSchema");
const { introspectionQuery } = require("graphql/utilities/introspectionQuery");
require("dotenv").config();

const graphQLClient = new GraphQLClient(process.env.STOREFRONT_ENDPOINT, {
const graphQLClient = new GraphQLClient(process.env.ADMIN_ENDPOINT, {
headers: {
"X-Shopify-Storefront-Access-Token": process.env.ACCESS_TOKEN
}
"X-Shopify-Access-Token": process.env.ACCESS_TOKEN,
},
});

graphQLClient.request(introspectionQuery).then(data => {
graphQLClient.request(introspectionQuery).then((data) => {
const build = buildClientSchema(data);
generateTypeScriptTypes(build, "./index.d.ts", { typePrefix: "" })
.then(() => {
process.exit(0);
})
.catch(err => {
.catch((err) => {
console.error(err);
process.exit(1);
});
Expand Down
Loading

0 comments on commit 6329620

Please sign in to comment.