Getting all shipping rates using GraphQL

chescko29
New Member
1 0 0

I'm trying to get all shipping rates from a Shopify store using GraphQL.

First, I tried with this query, using cursors and pagination:

 

 

query($cursor_profile: String = null, $cursor_location: String = null, $cursor_method: String = null) {
      deliveryProfiles(first:1, after: $cursor_profile) {
        pageInfo {
          hasNextPage
        }
        edges {
          cursor
          node {
            profileLocationGroups {
              locationGroupZones(first: 1, after: $cursor_location) {
                pageInfo {
                  hasNextPage
                }
                edges {
                  cursor
                  node {
                    methodDefinitions(first: 1, after: $cursor_method) {
                      pageInfo {
                        hasNextPage
                      }
                      edges {
                        cursor
                        node {
                          id
                          name
                        }
                      }
                    }
                  }
                }
              }
            }
          }
        }
      }
    }

 

 

*Please ignore that I'm always asking first:1, it's just an example. 

But, finally I decided to use bulkOperationRunQuery because it would be a mess handling the pagination, so I translated that query to a bulk operation query:

 

 

mutation {
  bulkOperationRunQuery(
   query: """
    {
      deliveryProfiles {
        edges {
          node {
            id
            profileLocationGroups {
              locationGroupZones {
                edges {
                  node {
                    methodDefinitions {
                      edges {
                        node {
                          id
                          name
                        }
                      }
                    }
                  }
                }
              }
            }
          }
        }
      }
    }
    """
  ) {
    bulkOperation {
      id
      status
    }
    userErrors {
      field
      message
    }
  }
}

 

 

But, I'm getting this response:

 

 

{
  "data": {
    "bulkOperationRunQuery": {
      "bulkOperation": null,
      "userErrors": [
        {
          "field": [
            "query"
          ],
          "message": "Queries that contain a connection field within a list field are not currently supported."
        },
        {
          "field": [
            "query"
          ],
          "message": "The parent 'node' field for a nested connection must select the 'id' field. Connection fields without 'id': locationGroupZones."
        }
      ]
    }
  },
  "extensions": {
    "cost": {
      "requestedQueryCost": 10,
      "actualQueryCost": 10,
      "throttleStatus": {
        "maximumAvailable": 1000,
        "currentlyAvailable": 990,
        "restoreRate": 50
      }
    }
  }
}

 

So, how can get all shipping rates using GraphQL?

Any sugestions?

Thanks.

0 Likes
_JB
Shopify Staff
Shopify Staff
817 96 177

Hey @chescko29,

The error messaging in these queries describes the problem, but I'll outline it a bit further with examples. In this case there are 2 problems, one can be resolved but the other will require you to use a different field in the query.

The first error  The parent 'node' field for a nested connection must select the 'id' field. Connection fields without 'id': locationGroupZonesoccurs when you attempt to run a bulk query without including the id field for nested connections. When preforming bulk queries this is a requirement.

The second error Queries that contain a connection field within a list field are not currently supported. is happening because the  profileLocationGroups field can't be used with bulk operations. The profileLocationGroups field contains a list of profiles as an array, this is the list referred to in the error message. These types of fields aren't currently supported through bulk operations. In this case you'll likely need to paginate in order to return the profile groups.

JB | Developer Support @ Shopify 
 - Was my reply helpful? Click Like to let me know! 
 - Was your question answered? Mark it as an Accepted Solution
 - To learn more visit Shopify.dev or the Shopify Web Design and Development Blog

0 Likes