ShopifyGraphql | MESA Docs
vendor/ShopifyGraphql.js
new ShopifyGraphql()Direct link to heading
Graphql Library
Returns
Void
ShopifyGraphql.send(query, variables[, connectionInfo, endpoint])Direct link to heading
Grapqhl call to Shopify.
Parameters
| Name | Type | Description |
|---|---|---|
| query | string |
Graphql query with variables. |
| variables | object |
Object with graphql query variables. |
| connectionInfo | ConnectionInfo | If you would like to connect to a separate Shopify website that Mesa is not installed on, create a Custom App and include a connectionInfo object. Optional |
| endpoint | string |
Override the Shopify GraphQL endpoint, for example to call a custom API version. Defaults to 'admin/graphql.json'. Optional |
Examples
// Query example
const query = `query {
shop {
name
primaryDomain {
url
host
}
}
}`;
const rest = Graphql.send(query, '');
Returns
objectGraphql response.
ShopifyGraphql.addOrUpdateMetafields(id, metafields)Direct link to heading
Adds a metafields to Shopify order. This function will add a metafield id to the payload if metafield already exits.
Parameters
| Name | Type | Description |
|---|---|---|
| id | string |
Shopify Order ID. |
| metafields | Array.<Metafields> |
Array of metafields. |
Examples
const shopifyOrderId = 1234;
const metafields = [{
namespace: "example",
key: "example_key",
value: "example_value"
}];
const response = Graphql.addOrUpdateMetafields(shopifyOrderId, metafields, "order");
Mesa.log.info('Graphql response: ', response);
Returns
objectGraphql response
ShopifyGraphql.addMetafields(id, metafields, entity)Direct link to heading
Adds a metafield to a Shopify entity. This function will throw an error if metafield exists and you do not pass an id.
Parameters
| Name | Type | Description |
|---|---|---|
| id | string |
Entity id. |
| metafields | Array.<Metafields> |
Array of metafields. |
| entity | string |
Entity: Order, Product |
Returns
Void
ShopifyGraphql.groupMetafieldsByKey(data)Direct link to heading
Takes metafield results, returns object keyed by the metafield key
Parameters
| Name | Type | Description |
|---|---|---|
| data | object |
Returns
objectmetafields
ShopifyGraphql.buildShopifyId(entity, id)Direct link to heading
Builds Shopfiy Graphql id.
Parameters
| Name | Type | Description |
|---|---|---|
| entity | string |
Shopfiy graphql entity. |
| id | string |
Shopify entity id. |
Returns
stringShopfiy graphql id
ShopifyGraphql.extractShopifyId(gid)Direct link to heading
Builds Shopfiy Graphql id.
Parameters
| Name | Type | Description |
|---|---|---|
| gid | string |
Shopfiy graphql id (ex: gid://shopify/ShippingLabelV2/637424009250) |
Returns
stringShopfiy id without the gid notation (ex: 637424009250)
{Object} Metafields()Direct link to heading
Metafields
Properties
Returns
Void
{Object} ConnectionInfo()Direct link to heading
connectionInfo parameter for Shopify calls
Properties
Returns
Void