Skip to content

Commit

Permalink
Merge branch 'master' of github.com:christophergregory/shopify-node-api
Browse files Browse the repository at this point in the history
  • Loading branch information
nodeit committed May 31, 2019
2 parents 86757ef + a13d05c commit 97684f4
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 1 deletion.
6 changes: 5 additions & 1 deletion lib/shopify.js
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ ShopifyAPI.prototype.makeRequest = function(endpoint, method, data, callback, re
code: response.statusCode
, error: jsonError || response.statusMessage
};
}
}

return callback(error, json, response.headers, options);
}
Expand Down Expand Up @@ -324,4 +324,8 @@ ShopifyAPI.prototype.has_header = function(response, header) {
return response.headers.hasOwnProperty(header) ? true : false;
};

ShopifyAPI.prototype.graphql = function(data, callback) {
this.makeRequest('/admin/api/graphql.json','POST', data, callback);
};

module.exports = ShopifyAPI;
46 changes: 46 additions & 0 deletions test/shopify.js
Original file line number Diff line number Diff line change
Expand Up @@ -700,3 +700,49 @@ describe('#delete', function(){

});
});

describe('#graphql', function(){
it('should return correct response', function(done){

var graphql_data = {
query: '{shop{id}}',
variables: {}
}
response = {
data: {
shop: {
id: 'gid:\/\/shopify\/Shop\/1234567'
}
},
extensions: {
cost: {
requestedQueryCost: 1,
actualQueryCost: 1,
throttleStatus: {
maximumAvailable: 1000.0,
currentlyAvailable: 999,
restoreRate: 50.0
}
}
}
};

var shopify_get = nock('https://myshop.myshopify.com')
.post('/admin/api/graphql.json')
.reply(200, response);

var Shopify = shopifyAPI({
shop: 'myshop',
shopify_api_key: 'abc123',
shopify_shared_secret: 'asdf1234',
shopify_scope: 'write_products',
redirect_uri: 'http://localhost:3000/finish_auth',
verbose: false
});

Shopify.graphql(graphql_data, function(err, data, headers){
expect(data).to.deep.equal(response);
done();
});
});
});

0 comments on commit 97684f4

Please sign in to comment.