0.0.6 • Published 12 months ago

@anthony809/shopify v0.0.6

Weekly downloads
-
License
ISC
Repository
github
Last release
12 months ago

Shopify GraphQl Package

Simple and fast package to query and mutate data from shopify, auto generating types

Import client

import Shopify from "@anthony809/shopify"
const storeUrl = "https://shop.myshopify.com/"
const StorefrontAccessToken = "12232344323kj432323"
const shopify = new Shopify(storeUrl,StorefrontAccessToken)
// Make a query
const query = `
    query getProducts {
        products(first: 5){
            nodes{
                title id handle
            }
        }
    }
`
// Make request, the response return ok:true|false, if true response return { ok:true,result:any }
const response = await shopify.request(query,{ type:"query",method:"products" })
// Always check if everything went fine
if(response.ok){  
    const data = response.result
    console.log(data) 
}

Import server

When import server, you can generate type for result

import type { HomeProductsResult } from "./types"
import ShopifyServer { type GenerateType } from "@anthony809/shopify/server"
const storeUrl = "https://shop.myshopify.com/"
const StorefrontAccessToken = "12232344323kj432323"
const shopifyServer = new ShopifyServer(storeUrl,StorefrontAccessToken)
// Make a query
const query = `
    query getProducts {
        products(first: 5){
            nodes{
                title id handle
            }
        }
    }
`
// Make request, the response return ok:true|false, if true response return { ok:true,result:any }
const generateTypeConfig:GenerateType = { name:"HomeProductsResult",path:"./test/types.ts"}
const response = await shopifyServer.request(query,{ type:"query",method:"products" },generateTypeConfig)
// Always check if everything went fine
if(response.ok){  
    const data:HomeProductsResult = response.result
    console.log(data) 
}
0.0.6

12 months ago

0.0.5

12 months ago

0.0.4

12 months ago

0.0.3

12 months ago

0.0.2

12 months ago

0.0.1

1 year ago