GraphQL Storefront API `malformed cursor` error

Raj13
New Member
5 0 0

Hi,

Can anyone help me figure out why this query throws a `malformed cursor` error when using the `cursor` it just returned?

query getCartProducts($cartId: ID!, $cursor: String) {
  node(id: $cartId) {
    ... on Checkout {
      lineItems(first: 2, after: $cursor) {
        edges {
          cursor
        }
      }
    }
  }
}
{
  "data": {
    "node": null
  },
  "errors": [
    {
      "message": "Malformed cursor",
      "locations": [
        {
          "line": 4,
          "column": 7
        }
      ],
      "path": [
        "node",
        "lineItems"
      ]
    }
  ]
}

Steps to recreate: 

  1. Create a checkout and get the checkout `id`
  2. Use the checkout `id` as the `cartId` variable and run the query
  3. Get the first `cursor` and run the query again with the `cursor` as the `cursor` variable

Storefront Access Token: 

9c83f3512c81adaa9f132e5a2b195545

 

Thanks

0 Likes
KarlOffenberger
Shopify Partner
1868 183 819

Hi Raj

Looks like a bug on that particular object because testing on others, either no cursor is returned, or even if it is, the query doesn't error out but simply returns an empty edges array.

Thus I wouldn't rely on the cursor's presence in the response for paging, but use pageInfo.hasNextPage instead.

Hope that helps and good catch - might want to report as a possible bug to @Shopify?

Liked this post? You might also like our fantastic upsell apps Candy Rack, Last Upsell post-purchase and Candy Cart or offer free gifts with Gift Box. All made with ❤️  and care by Digismoothie
0 Likes
Raj13
New Member
5 0 0

Thanks for taking a look Karl, I'm not going crazy then!

I can use `hasNextPage` to see whether there is a next page, but I can't actually get the next page, because that requires a `cursor`.

I've tried contacting the support team but they told me to make a post here. Do you know of any way to get in touch with the dev team?

Thanks

0 Likes
KarlOffenberger
Shopify Partner
1868 183 819

What I meant is that you get a cursor as long as there is a next page. When hasNextPage: false ignore the cursor and making the next call otherwise you end up with the error you're seeing.

Regarding Shopify devs, I suppose they do lurk around the hallows of forums but am not aware of ways to directly contact them - as a dev I'd be scared of users contacting me... the horror the horror :-D

Liked this post? You might also like our fantastic upsell apps Candy Rack, Last Upsell post-purchase and Candy Cart or offer free gifts with Gift Box. All made with ❤️  and care by Digismoothie
0 Likes
Raj13
New Member
5 0 0

Ah right, so you aren't getting that error until using the `cursor` when there are no more pages left? I'm seeing the error even if there are more pages, I haven't been able to use the `cursor` variable at all

Haha that's true!

0 Likes
KarlOffenberger
Shopify Partner
1868 183 819

Nope, not getting it. That is, I only ever get that error on your specific query on Checkout object. Other objects seem to work fine for the few I tried. And I only get it when using the cursor on after where hasNextPage: false. Have you checked that your checkout has more than 2 items? 

Liked this post? You might also like our fantastic upsell apps Candy Rack, Last Upsell post-purchase and Candy Cart or offer free gifts with Gift Box. All made with ❤️  and care by Digismoothie
0 Likes
Raj13
New Member
5 0 0

I'm only getting the error on `checkout` too, I've got a similar query running fine on `shop`. Strange, yeah there's definitely more than 2 items. Have you got a checkout `id` I could try?

0 Likes
KarlOffenberger
Shopify Partner
1868 183 819

Hey Raj

Okay this is embarassing, you were right all along. Checkout lineItem paging is broken no matter if you have hasNextPage: true or not. No idea what I did earlier this morning - going to blame myself answering questions before having coffee.

Coffee is always a good idea!

While this is definitely a bug IMO, being on the Checkout object I don't think we'd run in to this issue in practice - just set first:250 lineItems and hope billionaires don't fill up your cart with more until @Shopify fix it :-P

Sorry if I wasted your time!

Liked this post? You might also like our fantastic upsell apps Candy Rack, Last Upsell post-purchase and Candy Cart or offer free gifts with Gift Box. All made with ❤️  and care by Digismoothie
0 Likes
Raj13
New Member
5 0 0

Haha don't worry about it, I appreciate your help either way! I'm just glad that someone else has confirmed the bug, because I was convinced it was me doing something silly!

That's what I've done in the past, but I thought since I'm being all fancy and using GraphQL instead of JSON, I'll load data when I need to rather than all at once. Plus I can sleep easy knowing that even though its theoretically impossible, those billionaires can't break the site!

0 Likes
John_K1
Shopify Staff
Shopify Staff
4 0 2

Hi all! 

One of our team members is going to take a deeper look into this, but for now, I can pass along that the query seems to work if you pass the cartId and not the cursor value.

 

0 Likes