Shipments Query Giving Unexpected Error - Code 22

I’m working to pull down shipment data, and want to run the following query; however, I’m receiving an error “Unexpected Error” with the code 22.

Request ID: 5f033c577eaab23d39aa8d89

GraphQL Response:

{
  "errors": [
    {
      "message": "'shipments'"
    },
    {
      "message": "Unexpected Error",
      "operation": "shipments",
      "field": "data",
      "request_id": "5f033c577eaab23d39aa8d89",
      "code": 22
    }
  ],
  "data": {
    "shipments": {
      "request_id": "5f033c577eaab23d39aa8d89",
      "complexity": null,
      "data": null
    }
  }
}

GraphQL Query:

query($recordLimit:Int=5 $itemLimit:Int=10 $cursor:String="" $sort:String="created_date") {
  shipments {
    ...shipmentFields
  }
}

fragment shipmentFields on ShipmentsQueryResult {
  request_id
  complexity
  data(after:$cursor first:$recordLimit sort:$sort) {
    pageInfo {
      hasNextPage
      hasPreviousPage
      startCursor
      endCursor
    }
    edges {
      node {
        id
        legacy_id
        order_id
        user_id
        warehouse_id
        pending_shipment_id
        address {
          name
          address1
          address2
          city
          state
          country
          zip
          phone
        }
        picked_up
        created_date
        line_items(first:$itemLimit) {
          pageInfo {
            hasNextPage
            hasPreviousPage
            startCursor
            endCursor
          }
          edges {
            node {
              id
              line_item_id
              quantity
              line_item {
                sku
              }
            }
            cursor
          }
        }
        shipping_labels {
          status
          tracking_number
          carrier
          shipping_name
          shipping_method
          cost
          address {
            name
            address1
            address2
            city
            state
            country
            zip
            phone
          }
          shipment_line_items(first:$itemLimit) {
            pageInfo {
              hasNextPage
              hasPreviousPage
              startCursor
              endCursor
            }
            edges {
              node {
                id
                line_item_id
                quantity
                line_item {
                  sku
                }
              }
              cursor
            }
          }
        }
        order {
          id
          order_number
          partner_order_id
          shop_name
          fulfillment_status
          order_date
          email
          packing_note
        }
      }
      cursor
    }
  }
}

Hi @Brett!
I apologize for my delay in this
It seems to be related to the error you reported before, it is related to an error when calculating the complexity of the Query.
I will raise the priority on that ticket and will let you know as soon as I have an update about it.
Thanks again for the patience!
Tom

@tomasw Thanks for the info. I did try and do a very simplistic query with no sub-requests (no line items, no labels, etc.) and still got the same error.

Request ID: 5f04a43672441b6e92095b60

GraphQL Result:

{
  "errors": [
    {
      "message": "'shipments'"
    },
    {
      "message": "Unexpected Error",
      "operation": "shipments",
      "field": "data",
      "request_id": "5f04a43672441b6e92095b60",
      "code": 22
    }
  ],
  "data": {
    "shipments": {
      "request_id": "5f04a43672441b6e92095b60",
      "complexity": null,
      "data": null
    }
  }
}

GraphQL Query:

query($recordLimit:Int=5 $cursor:String="" $sort:String="created_date") {
  shipments {
    ...shipmentFields
  }
}

fragment shipmentFields on ShipmentsQueryResult {
  request_id
  complexity
  data(after:$cursor first:$recordLimit sort:$sort) {
    pageInfo {
      hasNextPage
      hasPreviousPage
      startCursor
      endCursor
    }
    edges {
      node {
        id
        legacy_id
        order_id
        user_id
        warehouse_id
        pending_shipment_id
        address {
          name
          address1
          address2
          city
          state
          country
          zip
          phone
        }
        picked_up
        created_date
      }
      cursor
    }
  }
}

Hi @brett!
In the meantime if you don’t use Fragments, does it work? (I don’t see the error if I don’t use that section)

For example:

query(
  $recordLimit: Int = 5
  $itemLimit: Int = 10
  $cursor: String
  $sort: String
  $specificOrder: String
) {
  orders(
    shop_name: "cocoa-via-dev.myshopify.com"
    partner_order_id: $specificOrder
  ) {
    request_id
    complexity
    data(first: $recordLimit, after: $cursor, sort: $sort) {
      pageInfo {
        hasNextPage
        hasPreviousPage
        startCursor
        endCursor
      }
      edges {
        node {
          id
          legacy_id
          shop_name
          order_date
          order_number
          partner_order_id
          required_ship_date
          total_price
          total_discounts
          tags
          authorizations {
            card_type
            date
            transaction_id
          }
          shipping_lines {
            title
            carrier
            method
            price
          }
          shipping_address {
            first_name
            last_name
            company
            address1
            address2
            city
            state
            state_code
            zip
            country
            country_code
            email
            phone
          }
          line_items(first: $itemLimit) {
            pageInfo {
              hasNextPage
              hasPreviousPage
              startCursor
              endCursor
            }
            edges {
              node {
                id
                legacy_id
                quantity
                subtotal
                sku
                price
                subtotal
                promotion_discount
                product {
                  warehouse_products {
                    price
                    value
                    value_currency
                  }
                }
              }
              cursor
            }
          }
        }
        cursor
      }
    }
  }
}

Instead of ...shipmentFields

Let me know if that is not a possibility for you.
Thanks again!

Hi @tomasw. So I removed the fragment and used the full query I’d like to have, and got the same error. I should also point out that I’d prefer to use fragments as the same information can be requested with different filters and a fragment is the way to impose consistency between the two queries.

Request ID: 5f05c4c73125226866915dcb

GraphQL Query:

query($recordLimit:Int=5 $itemLimit:Int=10 $cursor:String="" $sort:String="created_date") {
  shipments {
    request_id
  complexity
  data(after:$cursor first:$recordLimit sort:$sort) {
    pageInfo {
      hasNextPage
      hasPreviousPage
      startCursor
      endCursor
    }
    edges {
      node {
        id
        legacy_id
        order_id
        user_id
        warehouse_id
        pending_shipment_id
        address {
          name
          address1
          address2
          city
          state
          country
          zip
          phone
        }
        picked_up
        created_date
        line_items(first:$itemLimit) {
          pageInfo {
            hasNextPage
            hasPreviousPage
            startCursor
            endCursor
          }
          edges {
            node {
              id
              line_item_id
              quantity
              line_item {
                sku
              }
            }
            cursor
          }
        }
        shipping_labels {
          status
          tracking_number
          carrier
          shipping_name
          shipping_method
          cost
          address {
            name
            address1
            address2
            city
            state
            country
            zip
            phone
          }
          shipment_line_items(first:$itemLimit) {
            pageInfo {
              hasNextPage
              hasPreviousPage
              startCursor
              endCursor
            }
            edges {
              node {
                id
                line_item_id
                quantity
                line_item {
                  sku
                }
              }
              cursor
            }
          }
        }
        order {
          id
          order_number
          partner_order_id
          shop_name
          fulfillment_status
          order_date
          email
          packing_note
        }
      }
      cursor
    }
  }
  }
}

GraphQL Response:

{
  "errors": [
    {
      "message": "Unexpected Error",
      "operation": "shipments",
      "field": "data",
      "request_id": "5f05c4c73125226866915dcb",
      "code": 22
    }
  ],
  "data": {
    "shipments": {
      "request_id": "5f05c4c73125226866915dcb",
      "complexity": 41,
      "data": null
    }
  }
}

Thanks for confirming that @brett
Thanks for those details, I’m seeing that error on our logs, I believe this one might be a different error related to the header of the request, but let me investigate a bit.
I do agree that Fragment should be possible without that kind of errors, we’ll keep pushing for that ticket to be solved soon.
Thanks again for the patience!
Tom

@tomasw Any update on this? I’m still seeing an error when running a shipment query, and it’s been two weeks.

I tried both with a fragmented query, and the single query. Both returned error code 22.

Fragment Query Response

{
  "errors": [
    {
      "message": "Unexpected Error",
      "operation": "shipments",
      "field": "data",
      "request_id": "5f170aa30ecb0ed0fae45a72",
      "code": 22
    }
  ],
  "data": {
    "shipments": {
      "request_id": "5f170aa30ecb0ed0fae45a72",
      "complexity": 41,
      "data": null
    }
  }
}

Single Query Response

{
  "errors": [
    {
      "message": "Unexpected Error",
      "operation": "shipments",
      "field": "data",
      "request_id": "5f170bd72647607fe291f2f1",
      "code": 22
    }
  ],
  "data": {
    "shipments": {
      "request_id": "5f170bd72647607fe291f2f1",
      "complexity": 41,
      "data": null
    }
  }
}

Hi @brett
I apologize for this, it should be the same fix as Errors Returned For Successful Requests?
Checking it now

@tomasw No, I implemented work-around for malformed errors key returned in a response. This is refusing to return a result and is instead returning error code 22. Yes, it’s using the same fragment style query structure, but even in the other thread, I was still getting data back just with the extra errors key. Now I’m not getting any data back for a Shipments query.

Thanks for clarifying that @brett !
The error you are seeing is a timeout, it seems that results might be too much to filter them.
What about adding another filter to that?

Something like this:

shipments(date_from:"2020-01-01", date_to:"2020-01-02") {

Would that work for you?

@tomasw Thanks for that. So just so I understand: When I specify that I want the “first” or “last”, that restriction isn’t enough to limit the query because it’s limited to the first/last n after the result is returned. So if I have a large dataset, I need to use filters to limit the returned result size.

I ask because I’m making a similarly complex query to retrieve order data, and that doesn’t require that I use additional filters to limit the scope of the data pool.

Example Orders Query: 5f171dd67e842de12d553940
Example Shipments Query: 5f171e824d23be27ff3b4c06

That is correct @brett!
For example, if you search for first:10 orders, then we query ALL orders and then just get the first 10, but if you instead say first:10 + date_from:2020-01-01 + date_to:2020-01-02 then we will just be looking for a day, and then getting the first 10, which will make this faster and more efficient