diff --git a/package-lock.json b/package-lock.json index 7f5c6c2..511230f 100644 --- a/package-lock.json +++ b/package-lock.json @@ -10,6 +10,8 @@ "devDependencies": { "@types/google-apps-script": "^1.0.85", "gas-webpack-plugin": "^2.6.0", + "graphql-tag": "^2.12.6", + "shopify-admin-api-typings": "^1.2.2", "ts-loader": "^9.5.1", "webpack": "^5.96.1", "webpack-cli": "^5.1.4" @@ -911,6 +913,33 @@ "dev": true, "license": "ISC" }, + "node_modules/graphql": { + "version": "16.9.0", + "resolved": "https://registry.npmjs.org/graphql/-/graphql-16.9.0.tgz", + "integrity": "sha512-GGTKBX4SD7Wdb8mqeDLni2oaRGYQWjWHGKPQ24ZMnUtKfcsVoiv4uX8+LJr1K6U5VW2Lu1BwJnj7uiori0YtRw==", + "dev": true, + "license": "MIT", + "peer": true, + "engines": { + "node": "^12.22.0 || ^14.16.0 || ^16.0.0 || >=17.0.0" + } + }, + "node_modules/graphql-tag": { + "version": "2.12.6", + "resolved": "https://registry.npmjs.org/graphql-tag/-/graphql-tag-2.12.6.tgz", + "integrity": "sha512-FdSNcu2QQcWnM2VNvSCCDCVS5PpPqpzgFT8+GXzqJuoDd0CBncxCY278u4mhRO7tMgo2JjgJA5aZ+nWSQ/Z+xg==", + "dev": true, + "license": "MIT", + "dependencies": { + "tslib": "^2.1.0" + }, + "engines": { + "node": ">=10" + }, + "peerDependencies": { + "graphql": "^0.9.0 || ^0.10.0 || ^0.11.0 || ^0.12.0 || ^0.13.0 || ^14.0.0 || ^15.0.0 || ^16.0.0" + } + }, "node_modules/has-flag": { "version": "4.0.0", "resolved": "https://registry.npmjs.org/has-flag/-/has-flag-4.0.0.tgz", @@ -1444,6 +1473,16 @@ "node": ">=8" } }, + "node_modules/shopify-admin-api-typings": { + "version": "1.2.2", + "resolved": "https://registry.npmjs.org/shopify-admin-api-typings/-/shopify-admin-api-typings-1.2.2.tgz", + "integrity": "sha512-n9NSBPBKX+TSfAr8ibpXKoGdHCUCY6WBKV2FhD9xvjGG3DIqqUylqhC3OXKiWcrTQuyb3WnaRCvl16i3uhJMiQ==", + "dev": true, + "license": "MIT", + "peerDependencies": { + "graphql": ">=14" + } + }, "node_modules/slash": { "version": "3.0.0", "resolved": "https://registry.npmjs.org/slash/-/slash-3.0.0.tgz", @@ -1609,6 +1648,13 @@ "webpack": "^5.0.0" } }, + "node_modules/tslib": { + "version": "2.8.1", + "resolved": "https://registry.npmjs.org/tslib/-/tslib-2.8.1.tgz", + "integrity": "sha512-oJFu94HQb+KVduSUQL7wnpmqnfmLsOA/nAh6b6EH0wCEoK0/mPeXU6c3wKDV83MkOuHPRHtSXKKU99IBazS/2w==", + "dev": true, + "license": "0BSD" + }, "node_modules/typescript": { "version": "5.6.3", "resolved": "https://registry.npmjs.org/typescript/-/typescript-5.6.3.tgz", diff --git a/package.json b/package.json index f3d28d5..5d67aba 100644 --- a/package.json +++ b/package.json @@ -12,8 +12,14 @@ "devDependencies": { "@types/google-apps-script": "^1.0.85", "gas-webpack-plugin": "^2.6.0", + "graphql-tag": "^2.12.6", + "shopify-admin-api-typings": "^1.2.2", "ts-loader": "^9.5.1", "webpack": "^5.96.1", "webpack-cli": "^5.1.4" + }, + "graphql": { + "schema": "https://localhost:3001/graphql", + "documents": "**/*.{graphql,js,ts,jsx,tsx}" } } diff --git a/src/Product.ts b/src/Product.ts index c330eed..ee7d0e2 100644 --- a/src/Product.ts +++ b/src/Product.ts @@ -138,9 +138,7 @@ export class Product { variant.sku = this.sku variant.price = this.price sps.variants.push(variant) - let opt = new ShopifyVa - let options = new VariantOptionValueInput() - options.id = this.shopify_default_option_value_id + console.log("ToShopifyProductSet:\n" + JSON.stringify(sps, null, 2)) return sps } diff --git a/src/shopifyApi.ts b/src/shopifyApi.ts index 7cc41b1..c33e445 100644 --- a/src/shopifyApi.ts +++ b/src/shopifyApi.ts @@ -16,6 +16,8 @@ /// import { Config } from "./config" +import * as shopify from "shopify-admin-api-typings" +import gql from 'graphql-tag' const ss = SpreadsheetApp.getActive() @@ -731,7 +733,13 @@ export class ShopifyVariant { barcode?: string position?: number nodes?: ShopifyProductVariant[] - optionValues?: VariantOptionValueInput[] + //TODO: support multiple options + optionValues: [{}] = [ + { + optionName: "Title", + name: "Default Title" + } + ] } class PageInfo { @@ -802,7 +810,7 @@ export class ShopifyProductsResponse { } export class ShopifyProductSetQuery { - GQL: string = `mutation setProduct($productSet: ProductSetInput!) { + GQL = `mutation setProduct($productSet: ProductSetInput!) { productSet(input: $productSet) { product { id @@ -826,7 +834,7 @@ export class ShopifyProductSetQuery { JSON: JSON constructor(product: ShopifyProductSetInput, synchronous: boolean = true) { let j = `{ - "query": ${formatGqlForJSON(this.GQL)}, + "query": ${formatGqlForJSON(String(this.GQL))}, "variables": { "productSet": ${JSON.stringify(product)} } @@ -847,7 +855,15 @@ export class ShopifyProductSetInput { title: string vendor: string variants: ShopifyVariant[] - productOptions: ShopifyProductOption[] + //TODO: Support multiple product options + productOptions: [{}] = [ + { + name: "Title", + values: { + name: "Default Title" + } + } + ] } export class ProductVariantSetInput {