How to Use Shopify GraphiQL with Make.com Automation

If you use Make.com and Shopify, eventually you'll get to the point where you need to use the GraphiQL API as there are some operations that just aren't possible in the older REST API. 

Although Make.com offers a "Make a Shopify GraphiQL API Call" module, there is virtually no documentation on how to use the GraphiQL action within the Shopify module.

So after much trial and error, I wrote up a simple guide should any fellow Make/Shopify users need a resource in using this powerful, but inadequately described module. 

Queries & Mutations

If you are new to GraphiQL, one of the core concepts to understand is the notion of "queries" and "mutations". Simply put, a "query" is a request for data, and a "mutation" is a request to modify some data. Comparing to a REST api, a GraphiQL "query" is like a "get" and a GraphiQL "mutation" is like a "post" or "put"

 

Example Use Case for a Mutation: Create a Metaobject 

In this use case, I want to create new metaobjects in Shopify using the data contained in a list of items in a Google Spreadsheet. 

My Google spreadsheet contains columns for "category", "title", "description"

First, I created a metaobject definition in Shopify called "expertise" which contains three fields: "category", "title", & "description".

 

Next, I look for a mutation on the Shopify.dev GraphiQL reference for creating metaobjects and found metaObjectCreate

The "Examples" section contains everything we need to set this up in Make. 

Setting it Up in Make

I've added a Shopify "Make a GraphiQL api Call" module to my scenario and configured it use my store connection and most recent API version 

From the GraphiQL mutation reference page, copy "Mutation Reference" code and then paste it into the  "query" field.  
IMPORTANT: Delete any lines beginning with a hash. {eg "#Metaobject fields" as below }" from the pasted text. These are comments included in the example to show where the data goes in the mutation/query, but because the 'metaobject' value is being submitted as a variable, it needs to be removed or will cause an error. 

Note that when an item in a query/mutation begins with a $ sign, it means that used variable which is assigned separately. In this code, the variable is named "$metaobject"

Now we need to hook up the $metaobject variables in Make.

  1. In the Shopify "Make a GraphiQL api Call" module in Make, click "show advanced settings".
  2. Change "Variable data source" to "Collection"
  3. Go back to the Shopify.dev reference page and copy the example 'variable' JSON code. 
  4. Paste this code in the "Variables" box in Make to use as a template.
  5. Modify the variable code to fit the user case. Refer to the Shopify.dev documentation for info about the required fields so you know what is allowed/required.

    In my example use case, I know that "type" will always be set to "expertise", so I hardcoded that. I added my three data fields and mapped them to variables in Make. I also don't need to specify an online store templateSuffix, so I removed that as it is not required. Additionally, I removed "handle" as I do not have a reason to manually specify the handle (per the documentation, if this is omitted, it will be automatically generated, which is fine for this use case). My finished variable block looks like this:

A Few Gotchas

Here are a few items that are good to know when working with GraphiQL.

  1. If a metaobject definition has a field which value is limited to a list (as was the case with "category" in my project), you must encapsulate the field's value (which must exactly match what is defined in Shopify) as an escaped array string eg : "value":"[\"Web\']"  
  2. Make sure all data you are submitting escapes double quotes and converts newlines to "\n" or it will cause json validation errors. 
  3. The Shopify GraphiQL Explorer App is very handy for experimenting with queries/mutations and variables

Hope this points you in the right direction in trying to use the Make.com Shopify "Make a GraphiQL API Call" module!

 

 

 

Back to blog