Breaking Change!? Cursor-based pagination

Solved
fff_www
Shopify Partner
16 0 6

I see that post:
https://community.shopify.com/c/Shopify-APIs-SDKs/Updated-A-review-of-versioning-at-Shopify-what-you...
It states breaking changes in the page-based pagination.

But it also introduces a breaking change in cusor-based pagination,

namely the fact that the »after« field is not ignored anymore if empty, but throws a parse error.

Here it states that it is ignored: https://shopify.dev/concepts/graphql/pagination

Bildschirmfoto 2020-06-02 um 11.39.02.jpg

 

 

But here you see that it breaks:

 

products(first: 5, after:) {

 

Bildschirmfoto 2020-06-02 um 11.50.50.jpg

 

products(first: 5, after: "") {

or

products(first: 5, after: '') {

Bildschirmfoto 2020-06-02 um 11.51.14.jpg

 

The only way to bypass this is to remove the after field.

This breaks 10+ websites for me without me noticing at first, because the post at the beginning simply introduced cursor based pagination; i was like: yeah, i already have it... :(

 

Is this valid?
Can you confirm?

0 Likes
_JB
Shopify Staff
Shopify Staff
750 87 165

This is an accepted solution.

Hey @fff_www,

 

I just tested but wasn't able to replicate the issue. In all versions including 2020-04, the query still completes despite the cursor variable not being provided:

 

20-06-ivctk-a9uyo

 

I believe the parse error in this case is coming from your client, did you notice this issue start immediately after changing to the new version? If your client is throwing an error here, one option to consider is setting a default value of null for the cursor in the query. This should hopefully help prevent any errors by always providing a value to the query.

 

query ($numProducts: Int!, $cursor: String = null) {
...

If you still think this is on our end, please provide more details about how you're sending these calls and we can investigate further.

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
fff_www
Shopify Partner
16 0 6

Hey,

thanks for the quick reply!

 

Oh yes, it works with strictly setting the cursor to null.

Can you try with an empty cursor string?

 

Because what i've understood from the docs is that even though its an empty string it should work... but it breaks.

»The $cursor variable isn't required. When the $cursor variable is missing, the after argument is ignored.«

This would mean that the after argument should not break the code even if the resulting graphql string will be:

after:) // not set, breaks,
or
after: "") // empty string, breaks

after: null) // works

I mean... the fix is super easy, but it took me a while to understand the error... its not the expected behaviour from the docs, is it?

 

I used a simple post fetch request with javascript and a template string representation of the queryable object.
(Edit) Like here: https://github.com/Shopify/storefront-api-examples/blob/master/vanilla-graphql-client/example.js

0 Likes
_JB
Shopify Staff
Shopify Staff
750 87 165

Hey @fff_www,

 

I tried with an empty cursor field, empty string "" in the cursor field, and null in the cursor field. In each case the call completed as expected.

 

Since the call is working from my Insomnia HTTP client, this tells me the server is accepting the call with the empty or null cursor field as expected.

 

In your case, it seems the API call isn't being made due to your client throwing a parse error. If your client is making the call, you will get a response from Shopify with a X-Request-ID value in the response headers. If you have this, please provide the request_id and I can look for an error in our logs. 

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
fff_www
Shopify Partner
16 0 6

@_JB 96e05459-aace-4fb6-907f-9f96d09a03ff

0 Likes