Line items cannot be sorted, schema suggests they could be

Regardless of the ‘sort’ argument supplied, the line items will always be sorted by legacy_id in an order’s LineItemConnection. Are we using the query wrong, or is this feature not implemented?

query {
  order(id: "T****************3") {
    data {
      line_items(sort: "price") {
        edges {
          node {
            price
            legacy_id
          }
        }
      }
    }
  }
}

EDIT: I just noticed that in the example I provided, one could consider line items to be sorted by their price alphabetically, but this is completely coincidental and is just due to my failure to pick a more neutral example. Another example query (request_id: 62f3c90f67470bcbdf7cfded) returns:

"line_items": {
          "edges": [
            {
              "node": {
                "price": "25.0000",
                "legacy_id": 7*****073
              }
            },
            {
              "node": {
                "price": "6.0000",
                "legacy_id": 7*****074
              }
            },
            {
              "node": {
                "price": "45.0000",
                "legacy_id": 7*****075
              }
            },
            {
              "node": {
                "price": "4.0000",
                "legacy_id": 7*****076
              }
            },
            {
              "node": {
                "price": "2.0000",
                "legacy_id": 7*****077
              }
            },
            {
              "node": {
                "price": "94.0000",
                "legacy_id": 7*****078
              }
            },
            {
              "node": {
                "price": "12.0000",
                "legacy_id": 7*****895
              }
            }
          ]
        }

Hello @Gergely!

Welcome to our Public API Community, glad to have you here!

Wanted to let you know I started investigating this matter and will let you know as soon as i have an update!

Have a nice day!
TomasFD

1 Like

Hello @Gergely!

I’m forwarding the issue to our engineers as there seems to be a bug preventing the sort from working correctly in that connection.

Have a great day!
TomasFD

Hi @tomasfd!

Thank you for the update!

Do you have an ETA on when this bugfix will be shipped? We need to know whether we need to look at workarounds in the meantime.

Have a great day!
Gergely

Hey @Gergely,

Good news!
The Engineers are currently working on this ticket as we speak. I suspect a fix to be rolled out soon. I’ll let you know when that happens.

Thank you for your continued patience.

Best,
RayanP

1 Like

Hi!

This is still not working correctly. I have to use the line items sorting, because every time that I add a Line Item to the order, I need to retrieve its id. So, what I do is to retrieve the last line_item of the order, sorted by created_at (in the example it is made with legacy_id to test, but it is the same with any attibute you pass, it is not sorting at all).

I am sure this worked correctly for some time, but now it is not working again. This is very bad for us, because our software is integrated with Shiphero, and with this problem, when a user adds a new line item, it gets associated to another item’s id. Please help.

For example, you can see request id: 63bf05591648bb601983ae12.

Here I have the request:

What I am expecting is that the response gives me the last line_item that was created, but, as you can see, it is giving me another one (it is another sku!!).

image

Hi @sh-agent ! It would be very nice if you can help me with this. This is producing a very hard impact in our operations.

Hey Mario!

Thanks for reaching out.

It turns out a fix for this issue had actually been pushed but has since been rolled back. I’ll sync with the Engineer here to see if we can get another fix pushed for this issue.

Thanks for your patience!

Best,
RayanP

1 Like

Hi Rayan,

Thanks for your support. Maybe you can help me with a workaround for this. The only thing that I need is that every time I add a new Line Item to the order, I need to get its id. Do you think of a query to obtain this?

Hey @marioreinike,

Thanks for hanging in there!

Wanted to let you know that this Engineering Ticket is currently in review. I’ll take a look at a possible workaround but I expect a fix somewhat soon.

Let me know if there’s anything I can do to assist in the meantime.

Best,
RayanP

Hey @marioreinike,

Thanks for your patience here.

It looks like a fix has been pushed for this issue. Can you confirm that everything looks good on your end?

Best,
RayanP

Hi @sh-agent

TL;DR: sort is fixed, but last still doesn’t work

The sort argument is working correctly now, and first is also behaving as expected. This however, doesn’t solve the problem @marioreinike is having, as–unfortunately–there’s still an issue with the last argument: it’s returning the same line items as first would.

Examples
The following examples demonstrate the problem by querying the same order with different filter arguments on the line items.

  1. Using sort only (request_id: 63c02e7d3becd75b7947de33), works as expected
    Request:
query {
  order(id: "T**********1") {
    data {
      line_items(sort: "created_at") {
        edges {
          node {
            created_at
            id
          }
        }
      }
    }
  }
}

. Response:

"line_items": {
          "edges": [
            {
              "node": {
                "created_at": "2022-08-09T16:43:55",
                "id": "TG**********3MDcz"
              }
            },
            {
              "node": {
                "created_at": "2022-08-09T16:43:55",
                "id": "TG**********3MDc0"
              }
            },
            {
              "node": {
                "created_at": "2022-08-09T16:43:56",
                "id": "TG**********3MDc1"
              }
            },
            {
              "node": {
                "created_at": "2022-08-09T16:43:56",
                "id": "TG**********3MDc2"
              }
            },
            {
              "node": {
                "created_at": "2022-08-09T16:43:56",
                "id": "TG**********3MDc3"
              }
            },
            {
              "node": {
                "created_at": "2022-08-09T16:43:56",
                "id": "TG**********3MDc4"
              }
            },
            {
              "node": {
                "created_at": "2022-08-10T08:36:51",
                "id": "TG**********5ODk1"
              }
            }
          ]
        }
  1. Using sort with first (request_id: 63c02f36b9e7a6313a337a5f), works as expected
    Request:
query {
  order(id: "T**********1") {
    request_id
    data {
      line_items(sort: "created_at", first: 3) {
        edges {
          node {
            created_at
            id
          }
        }
      }
    }
  }
}

. Response:

"line_items": {
          "edges": [
            {
              "node": {
                "created_at": "2022-08-09T16:43:55",
                "id": "TG**********3MDcz"
              }
            },
            {
              "node": {
                "created_at": "2022-08-09T16:43:55",
                "id": "TG**********3MDc0"
              }
            },
            {
              "node": {
                "created_at": "2022-08-09T16:43:56",
                "id": "TG**********3MDc1"
              }
            }
          ]
        }
  1. Using sort with last (request_id: 63c0303bd1353f3a6b8ba2d3), doesn’t work
    Request:
query {
  order(id: "T**********1") {
    request_id
    data {
      line_items(sort: "created_at", last: 3) {
        edges {
          node {
            created_at
            id
          }
        }
      }
    }
  }
}

. Response:

"line_items": {
          "edges": [
            {
              "node": {
                "created_at": "2022-08-09T16:43:55",
                "id": "TG**********3MDcz"
              }
            },
            {
              "node": {
                "created_at": "2022-08-09T16:43:55",
                "id": "TG**********3MDc0"
              }
            },
            {
              "node": {
                "created_at": "2022-08-09T16:43:56",
                "id": "TG**********3MDc1"
              }
            }
          ]
        }

For the last one (sort with last) the expected response would have been:

"line_items": {
          "edges": [
            {
              "node": {
                "created_at": "2022-08-09T16:43:56",
                "id": "TG**********3MDc3"
              }
            },
            {
              "node": {
                "created_at": "2022-08-09T16:43:56",
                "id": "TG**********3MDc4"
              }
            },
            {
              "node": {
                "created_at": "2022-08-10T08:36:51",
                "id": "TG**********5ODk1"
              }
            }
          ]
        }
1 Like

Thanks @Gergely for all the details!

@sh-agent as he says, the sorting is working, but not as it should be. First, the last argument is not working, and second, not all of the attributes are working in the sorting. For example, if you sort by legacy_id, it doesn’t work. I think this deserves an investigation to solve the problem

But don’t worry, my issue is solved for now because I can make the query with the arguments:

first: 1, sort: "-created_at"

This will give me the last Line Item that was created because it is sorted descending.

So thanks @sh-agent for the support!

1 Like

Hey @Gergely and @marioreinike,

Thank you both for the information, it is very much appreciated. I will bring up the fixes that need to be done to the Engineer.

Thank you both for your patience and understanding.

Best,
RayanP