@anthony809/shopify
v0.0.6
Published
Simple and fast package to query and mutate data from shopify, auto generating types.
Downloads
25
Maintainers
Readme
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)
}