christophergregory / shopify-node-api

OAuth2 Module for Shopify API
MIT License
216 stars 74 forks source link

Add Graphql support #101

Closed richter-alex closed 5 years ago

richter-alex commented 5 years ago

Adds basic support for GraphQL queries and mutations in service of #100:

var shopifyAPI = require('shopify-node-api');

var Shopify = new shopifyAPI({
  shop: 'anprichter-test',
  shopify_api_key: '1b89be6b5198a41199ed5a52d804792d',
  access_token: '00f4a91c8f88268d23946233d8ce5d1c'
});

var query = `
mutation productUpdate($input: ProductInput!) {
  productUpdate(input: $input) {
    product {
      id
    }
    userErrors {
      field
      message
    }
  }
}
`;

var variables = {
    "input": {
        "id": "gid://shopify/Product/1326527184952",
        "variants": [
            {
                "price": 10,
                "title": "foobar",
                "options": [
                    "foo",
                    "bar",
                    "baz"
                ]
            },
            {
                "price": 20,
                "title": "baz",
                "options": [
                    "one",
                    "two",
                    "three"
                ]
            }
        ]
    }
};

var response = Shopify.graphql({"query": query, "variables": variables});

Tests are passing.

I noticed an issue that I'm not certain is with my local environment or the project itself to do with the added gzip support, but I'll make an issue for that. My changes do not appear to contribute to it.

nodeit commented 5 years ago

Thank you!