GraphQL, Ruby and syntax problem

Shopify Expert
3943 16 330

I am trying the mutation out to bulk update inventory. However, in trying to run the script, it bombs. I am not sure why.

The error I am seeing is: NameError: wrong constant name inventoryBulkAdjustQuantityAtLocation

 

How am I supposed to format this kind of mutation then? I am curious. Last thing I need to get working it seems.

 

BulkAdjustQuantityAtLocation = ShopifyGraphQLClient.parse <<-'GRAPHQL'
  mutation inventoryBulkAdjustQuantityAtLocation($inventoryItemAdjustments: [InventoryAdjustItemInput!]!, $locationId: ID!) {
    inventoryBulkAdjustQuantityAtLocation(inventoryItemAdjustments: $inventoryItemAdjustments, locationId: $locationId) {
      inventoryLevels {
        id
      }
      userErrors {
        field
        message
      }
    }
  }
  GRAPHQL
Custom Shopify Apps built just for you! hunkybill@gmail.com http://www.resistorsoftware.com
0 Likes
Shopify Staff
Shopify Staff
109 12 11

Hey @HunkyBill,

 

We played around with this one, and for this to work the mutation name needs to start with an uppercase letter. I believe the GraphQL gem is using the mutation name as a constant, which is why the capital is required. This worked for me:

 

BulkAdjustQuantityAtLocation = client.parse <<-'GRAPHQL'
  mutation InventoryBulkAdjustQuantityAtLocation($inventoryItemAdjustments: [InventoryAdjustItemInput!]!, $locationId: ID!) {
    inventoryBulkAdjustQuantityAtLocation(inventoryItemAdjustments: $inventoryItemAdjustments, locationId: $locationId) {
      inventoryLevels {
        id
      }
      userErrors {
        field
        message
      }
    }
  }
  GRAPHQL

JB | Developer Support @ Shopify
 - Was my reply helpful? Click Like to let me know! 
 - Was your question answered? Click Accept as Solution 

1 Like
Shopify Expert
3943 16 330

Ok, I will try that sometime. Simply removing the name works too.

 

Thanks

Custom Shopify Apps built just for you! hunkybill@gmail.com http://www.resistorsoftware.com
0 Likes