Dedicated to the Hydrogen framework, headless commerce, and building custom storefronts using the Storefront API.
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:
Storefront Access Token:
9c83f3512c81adaa9f132e5a2b195545
Thanks
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?
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
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 😄
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!
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?
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?
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 😛
Sorry if I wasted your time!
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!
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.
To learn more visit the Shopify Help Center or the Community Blog.
Hi John K
Thanks for looking in to this.
Querying with cartId works just fine. It's when the cart contains more line items than we fetch, we cannot page (i.e. after: $cursorFromPreviousResponse).
Steps to reproduce:
query getCartProducts($cartId: ID!, $cursor: String) {
node(id: $cartId) {
... on Checkout {
lineItems(first: 1, after: $cursor) {
pageInfo {
hasNextPage
hasPreviousPage
}
edges {
node {
title
}
cursor
}
}
}
}
}
// query variables
{
"cartId": "xxxxxxxxxxx-your-cart-id"
}
// response
{
"data": {
"node": {
"lineItems": {
"pageInfo": {
"hasNextPage": true,
"hasPreviousPage": false
},
"edges": [
{
"node": {
"title": "Pear"
},
"cursor": "eyJsYXN0X2lkIjoiMTcwYTBkZGM2Njg2N2VlN2ViODA3MzE1ZjIwYTQ1YjEiLCJsYXN0X3ZhbHVlIjoiMTcwYTBkZGM2Njg2N2VlN2ViODA3MzE1ZjIwYTQ1YjEifQ=="
}
]
}
}
}
}
Run the query again with above cursor from response as input to $cursor
// query variables
{
"cartId": "xxxxxxxxxxx-your-cart-id",
"cursor": "eyJsYXN0X2lkIjoiMTcwYTBkZGM2Njg2N2VlN2ViODA3MzE1ZjIwYTQ1YjEiLCJsYXN0X3ZhbHVlIjoiMTcwYTBkZGM2Njg2N2VlN2ViODA3MzE1ZjIwYTQ1YjEifQ=="
}
// response
{
"data": {
"node": null
},
"errors": [
{
"message": "Malformed cursor",
"locations": [
{
"line": 4,
"column": 7
}
],
"path": [
"node",
"lineItems"
]
}
]
}
Actual Result:
{
"data": {
"node": null
},
"errors": [
{
"message": "Malformed cursor",
"locations": [
{
"line": 4,
"column": 7
}
],
"path": [
"node",
"lineItems"
]
}
]
}
Expected result
{
"data": {
"node": {
"lineItems": {
"pageInfo": {
"hasNextPage": true,
"hasPreviousPage": true
},
"edges": [
{
"node": {
"title": "Pear",
"variant": {
"title": "M \/ Green \/ Regular"
}
},
"cursor": "xxxxxxxxxxx-next-cursor"
}
]
}
}
}
}
Hope that helps!
p.s. I could send you a detailed list of a few more bugs in the GQL Admin AP... possibly dupes you're aware of, but worth asking if you want.
Hi Pls have you found a walkaround to this?
Hi, were you able to find a solution?